Replies: 4 comments
-
I believe this may be doable on iOS as well by generating a sound file on the fly in the notification service extension. |
Beta Was this translation helpful? Give feedback.
-
Isn’t this a dupe of #1782? |
Beta Was this translation helpful? Give feedback.
-
@SeanPM5 @zacwest have you heard any updates related to TTS on ios? |
Beta Was this translation helpful? Give feedback.
-
This is entirely possible, though a bit involved. Using the Notification Service Extension, the application can retrieve an audio file generated from the TTS service and modify the notification payload to use this file as the alert sound. This, of course has some limitations: 24MB of memory and 30 second duration. In addition, if the application is closed/backgrounded, the audio file would need to be passed to the system. import UserNotifications
extension UNNotificationServiceExtension {
override func didReceive(_ notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationContent?) -> Void) {
// Get the URL to the sound file from the notification payload
let soundFileURL = notification.request.content.userInfo["soundFileURL"] as! URL
// Download the sound file
let task = URLSession.shared.downloadTask(with: soundFileURL) { url, _, error in
if let error = error {
print("Error downloading sound file: \\(error)")
} else if let url = url {
// Save the sound file to the Library/Sounds folder
do {
try FileManager.default.copyItem(at: url, to: URL(fileURLWithPath: Bundle.main.resourcePath! + "/Library/Sounds/custom_sound.wav"))
} catch {
print("Error saving sound file: \(error)")
}
// Set the notification sound to the downloaded sound file
completionHandler(UNNotificationContent(
body: notification.request.content.body,
title: notification.request.content.title,
sound: UNNotificationSound(named: "custom_sound.wav")))
}
}
task.resume()
}
} |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
When I'm on my Mac, I am typically using noise cancelling headphones and listening to music. So it's sometimes hard or impossible to hear TTS announcements on my Google Home or Alexa, or hear my phone vibrating for a new notification.
It would be pretty useful if you could leverage your Mac's built-in text to speech to send a TTS. Would be especially useful for important notifications that you don't want to miss ("intruder detected at back door!").
Describe the solution you'd like
Basic example, uses the default system voice and speaking rate under System Prefs -> Accessibility -> Spoken Content:
This would be equivalent to typing
say "This message will be spoken out loud by your Mac. Awesome!"
in the Terminal.Full example (optional), change the voice and speaking rate:
This would be equivalent to typing
say -v Alex "This message will be spoken out loud by your Mac. Awesome!" -r 240
in the Terminal.Describe alternatives you've considered
Rather than creating a secondary notify service like the examples above, it could be part of the default one service, and the user would just specify
type: tts
to make it speak rather than sending a text notification.Additional context
Beta Was this translation helpful? Give feedback.
All reactions