File size: 1,201 Bytes
b52991d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | package com.alphabot.app
import android.content.Context
import android.speech.tts.TextToSpeech
import java.util.Locale
class VoiceEngine(context: Context, private val onReady: () -> Unit) {
private var tts: TextToSpeech? = null
init {
tts = TextToSpeech(context) { status ->
if (status == TextToSpeech.SUCCESS) {
// ضبط اللكنة على اللغة العربية (مصر)
val result = tts?.setLanguage(Locale("ar", "EG"))
if (result != TextToSpeech.LANG_AVAILABLE && result != TextToSpeech.LANG_COUNTRY_AVAILABLE) {
tts?.language = Locale("ar")
}
// تعديل نبرة الصوت لتبدو وكأنها صوت رجل طبيعي ووقور
tts?.setPitch(0.8f) // نبرة أعمق وأرجح للرجولية
tts?.setSpeechRate(1.0f) // سرعة كلام طبيعية وغير متقطعة
onReady()
}
}
}
fun speak(text: String) {
tts?.speak(text, TextToSpeech.QUEUE_FLUSH, null, "AlphaBotVoice")
}
fun shutdown() {
tts?.stop()
tts?.shutdown()
}
}
|