LiTranslate-iOS/LiTranslate/Application/SpeechSynthesis.swift
Viktor Kalyniuk 823b3abe77 release v1.0
2022-09-10 20:46:05 +03:00

27 lines
731 B
Swift

//
// SpeechSynthesis.swift
// LiTranslate
//
// Created by Viktor Kalyniuk on 13.08.2022.
//
import Foundation
import AVFoundation
struct SpeechSynthesis {
static func play(_ string: String, language: Languages) {
let utterance = AVSpeechUtterance(string: string)
utterance.voice = AVSpeechSynthesisVoice(language: language.rawValue)
AVSpeechSynthesizer().speak(utterance)
}
static func canSynthesis(language: Languages) -> Bool {
let speechVoices = AVSpeechSynthesisVoice.speechVoices()
for speechVoice in speechVoices {
if speechVoice.language.prefix(2) == language.rawValue {
return true
}
}
return false
}
}