你好,感谢你阅读这篇文章!
在前台,我的应用程序为定时事件播放iOS7 AVSpeechUtterance。在后台,我向UILocalNotification的soundName属性传递了一个.wav文件名。这一切都行得通。
有没有办法将AVSpeechUtterance用作UILocalnotification的声音?我想要同样的合成在前景作为背景。
非常感谢!
发布于 2014-06-05 18:41:20
在appdelegate.m文件中创建此方法。别忘了在Appdelegate.h中导入AVFoundation/AVSpeechSynthesis.h
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Reminder"
message:notification.alertBody
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
AVSpeechUtterance *utterance = [AVSpeechUtterance
speechUtteranceWithString:[NSString stringWithFormat:@"%@",notification.alertBody]];
AVSpeechSynthesizer *synth = [[AVSpeechSynthesizer alloc] init];
utterance.volume = 10;
utterance.rate = 0.2;
utterance.pitchMultiplier = 1;
[synth speakUtterance:utterance];
// Request to reload table view data
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];
// Set icon badge number to zero
application.applicationIconBadgeNumber = 0;
}https://stackoverflow.com/questions/23520572
复制相似问题