wedyanessam commited on
Commit
d3f638a
·
verified ·
1 Parent(s): 7611b13

Update TTS_X/tts.py

Browse files
Files changed (1) hide show
  1. TTS_X/tts.py +12 -21
TTS_X/tts.py CHANGED
@@ -1,24 +1,15 @@
1
-
2
- import os
3
  import openai
4
- # حطي مفتاح OpenAI الخاص فيك هنا
5
- openai.api_key = os.getenv("OPENAI_API_KEY")
6
-
7
- def generate_audio_from_text(text, voice="onyx", output_path="output.mp3"):
8
- try:
9
- print(f"📦 جاري توليد الصوت باستخدام الصوت: {voice} ...")
10
- response = openai.audio.speech.create(
11
- model="tts-1-hd",
12
- voice=voice,
13
- input=text
14
- )
15
-
16
- with open(output_path, "wb") as f:
17
- f.write(response.content)
18
 
19
- print(f"✅ تم حفظ الصوت في: {output_path}")
20
- return output_path
21
- except Exception as e:
22
- print(f"❌ خطأ أثناء التوليد: {e}")
23
- return None
24
 
 
 
 
 
 
 
 
 
 
 
1
+ # tts.py
 
2
  import openai
3
+ import os
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
+ openai.api_key = os.getenv("OPENAI_API_KEY")
 
 
 
 
6
 
7
+ def generate_voice(text):
8
+ speech_file_path = "output.mp3"
9
+ response = openai.audio.speech.create(
10
+ model="tts-1",
11
+ voice="nova",
12
+ input=text,
13
+ )
14
+ response.stream_to_file(speech_file_path)
15
+ return speech_file_path