我正在尝试实现读取标签文本并将其分配给本地通知声音。每当本地通知触发时,它的声音应类似于“嘿,您的+ label.text +文件已下载。
请帮助我制作以上脚本。
let content = UNMutableNotificationContent()
content.title = "Title"
content.body = "Body"
content.sound = UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "TestIdentifier", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
我有文字要语音,但我不怎么合并两者
import AVFoundation
let string = "Hello, World!"
let utterance = AVSpeechUtterance(string: string)
utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
let synth = AVSpeechSynthesizer()
synth.speak(utterance)
答案 0 :(得分:0)
在iOS中看起来不太可能。自定义通知声音应该是UNNotificationSound
类的实例,AVSpeechSynthesisVoice
对此无能为力。
content.sound = UNNotificationSound(named: soundName)
请检查以下链接。 raywenderlich