gpt4 book ai didi

ios - AVSpeechUtterance 作为 UILocalNotification 声音

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:39:28 26 4
gpt4 key购买 nike

您好,感谢您阅读本文!

在前台,我的应用程序为定时事件播放 iOS7 AVSpeechUtterance。在后台,我将 .wav 文件名传递给 UILocalNotificationsoundName 属性。这一切都有效。

有没有办法将 AVSpeechUtterance 用作 UILocalnotification 的声音?我希望前景中的合成与背景中的相同。

非常感谢!

最佳答案

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;
}

关于ios - AVSpeechUtterance 作为 UILocalNotification 声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23520572/

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