Xamarin ios歌曲不总是在扬声器上播放



我是Xamarin用户,从文本到语音api点击这里查看

我已经设法在我的应用程序上实现了它,但有些时候,歌曲在手机扬声器上播放,有些人在录制歌曲后在耳机上说话

问题:

如何使歌曲始终在手机扬声器上播放

代码如下:

var config = SpeechConfig.FromSubscription("xxxx", "xxxx");
config.SpeechSynthesisVoiceName = MicosoftTranslater.MySpeakerlanguagesList( "fr-FR");
var synthesizer = new SpeechSynthesizer(config);
await synthesizer.SpeakTextAsync("I am playing from phone speaker");

谢谢你的帮助

关键是使用适当的AVAudioSessionCategory调用SetCategory并将会话设置为活动

:

var session = AVAudioSession.SharedInstance();
session.SetCategory(AVAudioSessionCategory.Playback);
session.SetActive(true);

你可以使用DependencyService在你的ios项目中设置它。您可以参考https://learn.microsoft.com/en-us/answers/questions/320860/isimpleaudioplayer-issues-on-ios-and-with-speechre.html.

最新更新