ios – 如何通过呼叫接收扬声器播放AVSpeechSynthesizer?

ios – 如何通过呼叫接收扬声器播放AVSpeechSynthesizer?,第1张

概述我喜欢通过呼叫接收扬声器播放音频,目前我使用它来播放一些文本作为音频. AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:_strTextCheck]; AVSpeechSynthesizer *syn = [[AVSpeechSynthesizer alloc] init]; 我喜欢通过呼叫接收器扬声器播放音频,目前我使用它来播放一些文本作为音频.

AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:_strTextCheck];    AVSpeechSynthesizer *syn = [[AVSpeechSynthesizer alloc] init];    [syn speakUtterance:utterance];

我得到了但这不适用于AVSpeechSynthesizer:

[AVAudioSession  overrIDeOutputAudioPort:AVAudioSessionPortOverrIDeSpeaker error:&error];

正确地说它正常的扬声器,但我想通过呼叫接收器扬声器播放,是否可以这样做?

解决方法 默认行为是通过呼叫接收器播放.因此,如果你取消设置覆盖 – 或者不首先设置它 – 你应该得到你所追求的行为:

[[AVAudioSession sharedInstance]      overrIDeOutputAudioPort:AVAudioSessionPortOverrIDeNone                       error:nil];

这是一个完整的例子.您还需要设置audioSession类别.

- (voID)playVoice {    [[AVAudioSession sharedInstance]              setcategory:AVAudioSessioncategoryPlayAndRecord                  error:nil];    //try one or the other but not both...    //[self playVoiceOnSpeaker:@"test test test"];    [self playVoiceOnReceiver:@"test test test"];}-(voID)playVoiceOnSpeaker:(Nsstring*)str{    [[AVAudioSession sharedInstance]           overrIDeOutputAudioPort:AVAudioSessionPortOverrIDeSpeaker                           error:nil];    [self playVoiceByComputer:str];}-(voID)playVoiceOnReceiver:(Nsstring*)str{    [[AVAudioSession sharedInstance]         overrIDeOutputAudioPort:AVAudioSessionPortOverrIDeNone                           error:nil];    [self playVoiceByComputer:str];}-(voID)playVoiceByComputer:(Nsstring*)str{    AVSpeechUtterance *utterance =           [AVSpeechUtterance speechUtteranceWithString:str];    AVSpeechSynthesizer *syn = [[AVSpeechSynthesizer alloc] init];    [syn speakUtterance:utterance];}
总结

以上是内存溢出为你收集整理的ios – 如何通过呼叫接收扬声器播放AVSpeechSynthesizer?全部内容,希望文章能够帮你解决ios – 如何通过呼叫接收扬声器播放AVSpeechSynthesizer?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1049957.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存