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

Xamarin ios song does not always play on speaker

我是 Xamarin 用户,来自文本到语音 api click here to see

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

问题:

如何让歌曲始终在phone的扬声器上播放

代码如下:

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 to set it in your ios project.You could refer to https://docs.microsoft.com/en-us/answers/questions/320860/isimpleaudioplayer-issues-on-ios-and-with-speechre.html.