gpt4 book ai didi

objective-c - AVSpeechSynthesizer 在模拟器上工作,但在设备上不工作

转载 作者:太空狗 更新时间:2023-10-30 03:48:55 30 4
gpt4 key购买 nike

我一直在尝试学习 AVSpeechSynthesis。该代码在 iOS 模拟器(在 iPad 和 iOS 上)中运行良好,但文本到语音功能在我的 iPad 上根本不起作用。这是我的代码。

    - (void)viewDidLoad
{

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.



//Load Model
self.string = @"Hello World";
self.utterance = [[AVSpeechUtterance alloc] initWithString:self.string];
self.utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
self.utterance.rate = (float) 0.25;

//Load UI
self.textLabel.text = self.string;


}

- (IBAction)startSpeaking:(id)sender {

self.speechSynthesizer = [[AVSpeechSynthesizer alloc] init];

if ([self.speechSynthesizer isSpeaking]) {

[self.speechSynthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryWord];


} else {

[self.speechSynthesizer speakUtterance:self.utterance];

}
}

更新:AVSpeechSyntheSizer 正在工作但没有声音所以我有一个 UILabel,其文本与 UI 上的 AVSpeechUtterance 相同。我实现了 AVSpeechSynthesizerDelegate,这样当我点击 startSpeaking: 文本标签时,当前单词就会变成红色。所以我知道 AVSpeechSynthesizer 一定在工作,因为它正在进行委托(delegate)调用,但我不明白为什么我听不到它。音量已调高,并且没有其他应用程序正在播放音频。

最佳答案

您的手机是否处于静音模式?这也会使合成器静音。

关于objective-c - AVSpeechSynthesizer 在模拟器上工作,但在设备上不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24093434/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com