Dan*_*ons 5 objective-c ios7 avspeechsynthesizer
我一直在努力学习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];
}
}
Run Code Online (Sandbox Code Playgroud)
更新:AVSpeechSyntheSizer工作但没有声音 所以我有一个UILabel与UI上的AVSpeechUtterance相同的文本.我实现了AVSpeechSynthesizerDelegate,这样当我点击startSpeaking时:文本标签将当前单词变为红色.所以我知道AVSpeechSynthesizer必须工作,因为它正在进行委托调用,但我无法弄清楚为什么我听不到它.音量上升,没有其他应用播放音频.
| 归档时间: |
|
| 查看次数: |
2874 次 |
| 最近记录: |