AVSpeechSynthesizer适用于模拟器,但不适用于设备 [英] AVSpeechSynthesizer works on simulator but not on device

查看:180
本文介绍了AVSpeechSynthesizer适用于模拟器,但不适用于设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been trying to learn AVSpeechSynthesis. The code works fine in the iOS Simulator (both on iPad and iOS) but the text to speech feature doesn't work at all on my iPad. Here's my code.

    - (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必须工作,因为它正在进行委托调用,但我无法弄清楚为什么我听不到它。音量很高,没有其他应用播放音频。

UPDATE: AVSpeechSyntheSizer is working but no sound So I have a UILabel with the same text as the AVSpeechUtterance on the UI. I implemented AVSpeechSynthesizerDelegate so that when I hit startSpeaking: the text label turns the current word red. So I know that AVSpeechSynthesizer must be working because it's making delegate calls but I can't figure out why I can't hear it. The volume is up and no other apps are playing audio.

推荐答案

你有手机处于静音模式吗?这也使合成器静音。

Do you have the phone in silent mode? That silences the synthesizer as well.

这篇关于AVSpeechSynthesizer适用于模拟器,但不适用于设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆