Files
Leeksov 4647310322 GLEGram 12.5 — Initial public release
Based on Swiftgram 12.5 (Telegram iOS 12.5).
All GLEGram features ported and organized in GLEGram/ folder.

Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass,
Font Replacement, Fake Profile, Chat Export, Plugin System, and more.

See CHANGELOG_12.5.md for full details.
2026-04-06 09:48:12 +03:00

60 lines
1.7 KiB
Swift

import Foundation
import AVFoundation
import AccountContext
// 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 class SpeechSynthesizerHolder: NSObject, AVSpeechSynthesizerDelegate {
private var speechSynthesizer: AVSpeechSynthesizer
public var completion: () -> Void = {}
init(speechSynthesizer: AVSpeechSynthesizer) {
self.speechSynthesizer = speechSynthesizer
super.init()
self.speechSynthesizer.delegate = self
}
deinit {
self.stop()
}
public func stop() {
self.speechSynthesizer.stopSpeaking(at: .immediate)
}
public func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance) {
self.completion()
}
}
public func supportedSpeakLanguages() -> Set<String> {
var languages: [String] = []
for voice in AVSpeechSynthesisVoice.speechVoices() {
let components = voice.language.components(separatedBy: "-")
if let language = components.first {
languages.append(language)
}
}
return Set(languages)
}
public func speakText(context: AccountContext, text: String) -> SpeechSynthesizerHolder? {
guard !text.isEmpty else {
return nil
}
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)
return SpeechSynthesizerHolder(speechSynthesizer: speechSynthesizer)
}