AlphaBot / VoiceEngine.kt
Jduxydje's picture
Create VoiceEngine.kt
b52991d verified
Raw History Blame Contribute Delete
1.2 kB
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()
}
}