Download VoiceEngine.kt from Jduxydje/AlphaBot: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/Jduxydje/AlphaBot/resolve/main/VoiceEngine.kt
- Command line
-
hf download hf://Jduxydje/AlphaBot/VoiceEngine.kt
-
curl -L -o VoiceEngine.kt https://huggingface.co/Jduxydje/AlphaBot/resolve/main/VoiceEngine.kt
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() | |
| } | |
| } | |