mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
19 lines
606 B
Swift
19 lines
606 B
Swift
import Foundation
|
|
import AVFoundation
|
|
|
|
// Incuding at least one Objective-C class in a swift file ensures that it doesn't get stripped by the linker
|
|
private final class LinkHelperClass: NSObject {
|
|
}
|
|
|
|
public func speakText(_ text: String) {
|
|
guard !text.isEmpty else {
|
|
return
|
|
}
|
|
let speechSynthesizer = AVSpeechSynthesizer()
|
|
let utterance = AVSpeechUtterance(string: text)
|
|
if #available(iOS 11.0, *), let language = NSLinguisticTagger.dominantLanguage(for: text) {
|
|
utterance.voice = AVSpeechSynthesisVoice(language: language)
|
|
}
|
|
speechSynthesizer.speak(utterance)
|
|
}
|