Spaces:
Runtime error
Runtime error
Update TTS_X/tts.py
Browse files- TTS_X/tts.py +18 -29
TTS_X/tts.py
CHANGED
|
@@ -1,36 +1,25 @@
|
|
| 1 |
-
|
| 2 |
-
from TTS.api import TTS
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
-
|
| 6 |
-
# تحديد الجهاز
|
| 7 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 8 |
-
print(f"🚀 الجهاز المستخدم: {device}")
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
print(f"❌ ملف الصوت للتقليد غير موجود: {speaker_wav_path}")
|
| 13 |
-
return
|
| 14 |
|
|
|
|
| 15 |
try:
|
| 16 |
-
print("📦 جاري
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
print(e)
|
| 22 |
-
return
|
| 23 |
-
|
| 24 |
-
try:
|
| 25 |
-
print("🎤 جاري توليد الصوت...")
|
| 26 |
-
tts.tts_to_file(
|
| 27 |
-
text=text,
|
| 28 |
-
speaker_wav=speaker_wav_path,
|
| 29 |
-
language=language,
|
| 30 |
-
file_path=output_path
|
| 31 |
)
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
-
print("❌ خطأ أثناء
|
| 35 |
-
|
| 36 |
|
|
|
|
| 1 |
+
# openai_tts.py
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
import openai
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
# حطي مفتاح OpenAI الخاص فيك هنا
|
| 6 |
+
openai.api_key = "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"
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
def generate_audio_from_text(text, voice="onyx", output_path="output.mp3"):
|
| 9 |
try:
|
| 10 |
+
print(f"📦 جاري توليد الصوت باستخدام الصوت: {voice} ...")
|
| 11 |
+
response = openai.audio.speech.create(
|
| 12 |
+
model="tts-1-hd",
|
| 13 |
+
voice=voice,
|
| 14 |
+
input=text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
)
|
| 16 |
+
|
| 17 |
+
with open(output_path, "wb") as f:
|
| 18 |
+
f.write(response.content)
|
| 19 |
+
|
| 20 |
+
print(f"✅ تم حفظ الصوت في: {output_path}")
|
| 21 |
+
return output_path
|
| 22 |
except Exception as e:
|
| 23 |
+
print(f"❌ خطأ أثناء التوليد: {e}")
|
| 24 |
+
return None
|
| 25 |
|