Update test app.py
Browse filesadd: response.stream_to_file("output.mp3") to Streaming audio
app.py
CHANGED
|
@@ -6,17 +6,20 @@ from openai import OpenAI
|
|
| 6 |
|
| 7 |
def tts(text, model, voice, api_key):
|
| 8 |
if api_key == '':
|
| 9 |
-
raise gr.Error('Please enter your
|
| 10 |
else:
|
| 11 |
try:
|
| 12 |
client = OpenAI(api_key=api_key)
|
| 13 |
|
| 14 |
response = client.audio.speech.create(
|
| 15 |
-
model=model, # "tts-1","tts-1
|
| 16 |
-
voice=voice, # '
|
| 17 |
input=text,
|
| 18 |
)
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
except Exception as error:
|
| 21 |
# Handle any exception that occurs
|
| 22 |
raise gr.Error("An error occurred while generating speech. Please check your API key and try again.")
|
|
@@ -33,12 +36,12 @@ def tts(text, model, voice, api_key):
|
|
| 33 |
|
| 34 |
|
| 35 |
with gr.Blocks() as demo:
|
| 36 |
-
gr.Markdown("# <center>
|
| 37 |
-
#gr.HTML("You can also access the Streaming
|
| 38 |
with gr.Row(variant='panel'):
|
| 39 |
-
api_key = gr.Textbox(type='password', label='OpenAI API Key', placeholder='Enter your API key to access the TTS
|
| 40 |
-
model = gr.Dropdown(choices=['tts-1','tts-1
|
| 41 |
-
voice = gr.Dropdown(choices=['
|
| 42 |
|
| 43 |
text = gr.Textbox(label="Input text", placeholder="Enter your text and then click on the 'Text-To-Speech' button, or simply press the Enter key.")
|
| 44 |
btn = gr.Button("Text-To-Speech")
|
|
|
|
| 6 |
|
| 7 |
def tts(text, model, voice, api_key):
|
| 8 |
if api_key == '':
|
| 9 |
+
raise gr.Error('Please enter your API Key')
|
| 10 |
else:
|
| 11 |
try:
|
| 12 |
client = OpenAI(api_key=api_key)
|
| 13 |
|
| 14 |
response = client.audio.speech.create(
|
| 15 |
+
model=model, # "tts-1-hd","tts-1"
|
| 16 |
+
voice=voice, # 'echo', 'alloy', 'fable', 'onyx', 'nova', 'shimmer'
|
| 17 |
input=text,
|
| 18 |
)
|
| 19 |
|
| 20 |
+
response.stream_to_file("output.mp3")
|
| 21 |
+
|
| 22 |
+
|
| 23 |
except Exception as error:
|
| 24 |
# Handle any exception that occurs
|
| 25 |
raise gr.Error("An error occurred while generating speech. Please check your API key and try again.")
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
with gr.Blocks() as demo:
|
| 39 |
+
gr.Markdown("# <center> Text-To-Speech API Key </center>")
|
| 40 |
+
#gr.HTML("You can also access the Streaming for TTS by clicking this <a href='https://huggingface.co/Wromo/OpenAI-TTS-1DH-Text-to-Speech/'>© WROMO Text to Speech</a>")
|
| 41 |
with gr.Row(variant='panel'):
|
| 42 |
+
api_key = gr.Textbox(type='password', label='OpenAI API Key', placeholder='Enter your API key to access the TTS')
|
| 43 |
+
model = gr.Dropdown(choices=['tts-1-hd','tts-1'], label='Model', value='tts-1-hd')
|
| 44 |
+
voice = gr.Dropdown(choices=['echo', 'alloy', 'fable', 'onyx', 'nova', 'shimmer'], label='Voice Options', value='echo')
|
| 45 |
|
| 46 |
text = gr.Textbox(label="Input text", placeholder="Enter your text and then click on the 'Text-To-Speech' button, or simply press the Enter key.")
|
| 47 |
btn = gr.Button("Text-To-Speech")
|