首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >作为UILocalNotification声音的AVSpeechUtterance

作为UILocalNotification声音的AVSpeechUtterance
EN

Stack Overflow用户
提问于 2014-05-07 22:27:21
回答 1查看 670关注 0票数 3

你好,感谢你阅读这篇文章!

在前台,我的应用程序为定时事件播放iOS7 AVSpeechUtterance。在后台,我向UILocalNotificationsoundName属性传递了一个.wav文件名。这一切都行得通。

有没有办法将AVSpeechUtterance用作UILocalnotification的声音?我想要同样的合成在前景作为背景。

非常感谢!

EN

回答 1

Stack Overflow用户

发布于 2014-06-05 18:41:20

appdelegate.m文件中创建此方法。别忘了在Appdelegate.h中导入AVFoundation/AVSpeechSynthesis.h

代码语言:javascript
复制
- (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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23520572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档