Merge commit '458f1ca5847b597429699c88a96fcb83ae408bbd'

This commit is contained in:
Ali 2021-02-18 17:55:36 +04:00
commit b640157f61
2 changed files with 33 additions and 0 deletions

15
submodules/Speak/BUILD Normal file
View File

@ -0,0 +1,15 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "Speak",
module_name = "Speak",
srcs = glob([
"Sources/**/*.swift",
]),
deps = [
"//submodules/Display:Display",
],
visibility = [
"//visibility:public",
],
)

View File

@ -0,0 +1,18 @@
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)
}