Xamarin iOS:使用 AVSpeechSynthesizer 没有发出任何声音?

Xamarin iOS: Doesn't make any sound using AVSpeechSynthesizer?

我尝试按照 Xamarin 文档中有关语音转文本的示例代码进行操作。 android 部分适用于我的 android phone 但在 iPhone 上测试它没有发出任何声音。我添加了委托函数 "DidStartSpeechUtterance" 并且它确实调用了委托函数但是 phone.

没有声音
            var speechSynthesizer = new AVSpeechSynthesizer();

        var speechUtterance = new AVSpeechUtterance(text)
        {
            Rate = AVSpeechUtterance.MaximumSpeechRate / 4,
            Voice = AVSpeechSynthesisVoice.FromLanguage("en-US"),
            Volume = 0.5f,
            PitchMultiplier = 1.0f
        };
        speechSynthesizer.DidStartSpeechUtterance += (sender, e) =>
        {
            System.Diagnostics.Debug.WriteLine("Am I get called");
        };

        speechSynthesizer.SpeakUtterance(speechUtterance);

它适用于模拟器 iPhone SE iOS 10.2,但不适用于实际设备。

遗憾的是,我真的没有直接的答案给你,但是:

可以试试 James Montemagno 的 nuget 包是否适合你:

https://github.com/jamesmontemagno/TextToSpeechPlugin

这样做是为了抽象实现,以便您可以从(共享的)可移植 class 库中使用它 - 它还可以帮助您共享更多代码。我很好奇这是否对你有用。如果这不起作用,要么是其他地方出了问题(在语音合成器部分之外)

我解决了这个问题:

AVFoundation.AVAudioSession.SharedInstance().SetCategory(‌ AVFoundation.AVAudio‌ SessionCategory.Reco‌ rd); .我将其更改为 PlayAndRecord 以使其正常工作。

我发现问题了我设置了这条语句 AVFoundation.AVAudioSession.SharedInstance().SetCategory(‌ AVFoundation.AVAudio‌ SessionCategory.Reco‌ rd); .我将其更改为 PlayAndRecord 以使其正常工作