Wromo commited on
Commit
02d73d0
·
verified ·
1 Parent(s): f7bcc0a

Update app.py

Browse files

Add new model voice end olso language choices!

Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -3,7 +3,7 @@ import os
3
  import tempfile
4
  from openai import OpenAI
5
 
6
- def tts(text, model, voice, api_key):
7
  if api_key == '':
8
  raise gr.Error('Please enter your API Key')
9
  else:
@@ -13,6 +13,7 @@ def tts(text, model, voice, api_key):
13
  response = client.audio.speech.create(
14
  model=model,
15
  voice=voice,
 
16
  input=text,
17
  )
18
 
@@ -22,8 +23,8 @@ def tts(text, model, voice, api_key):
22
 
23
  return temp_file_path
24
  except Exception as error:
25
- raise gr.Error("An error occurred while generating speech. Please check your API key and try again.")
26
  print(str(error))
 
27
 
28
  with gr.Blocks() as demo:
29
  gr.Markdown("# <center> Text-To-Speech API Key </center>")
@@ -31,13 +32,18 @@ with gr.Blocks() as demo:
31
  with gr.Row(variant='panel'):
32
  api_key = gr.Textbox(type='password', label='OpenAI API Key', placeholder='Enter your API key to access the TTS')
33
  model = gr.Dropdown(choices=['tts-1', 'tts-1-hd'], label='Model', value='tts-1-hd')
34
- voice = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='Voice Options', value='echo')
 
 
 
 
 
35
 
36
  text = gr.Textbox(label="Input text", placeholder="Enter your text and then click the 'Text-To-Speech' button or press Enter.")
37
  btn = gr.Button("Text-To-Speech")
38
  output_audio = gr.Audio(label="Speech Output")
39
 
40
- text.submit(fn=tts, inputs=[text, model, voice, api_key], outputs=output_audio, api_name="tts_enter_key", concurrency_limit=None)
41
- btn.click(fn=tts, inputs=[text, model, voice, api_key], outputs=output_audio, api_name="tts_button", concurrency_limit=None)
42
 
43
- demo.launch()
 
3
  import tempfile
4
  from openai import OpenAI
5
 
6
+ def tts(text, model, voice, language, api_key):
7
  if api_key == '':
8
  raise gr.Error('Please enter your API Key')
9
  else:
 
13
  response = client.audio.speech.create(
14
  model=model,
15
  voice=voice,
16
+ language=language, # Parametrul adăugat pentru limbă
17
  input=text,
18
  )
19
 
 
23
 
24
  return temp_file_path
25
  except Exception as error:
 
26
  print(str(error))
27
+ raise gr.Error("An error occurred while generating speech. Please check your API key and try again.")
28
 
29
  with gr.Blocks() as demo:
30
  gr.Markdown("# <center> Text-To-Speech API Key </center>")
 
32
  with gr.Row(variant='panel'):
33
  api_key = gr.Textbox(type='password', label='OpenAI API Key', placeholder='Enter your API key to access the TTS')
34
  model = gr.Dropdown(choices=['tts-1', 'tts-1-hd'], label='Model', value='tts-1-hd')
35
+ voice = gr.Dropdown(choices=['alloy', 'ash', 'coral', 'echo', 'fable', 'onyx', 'nova', 'sage', 'shimmer'], label='Voice Options', value='echo')
36
+ language = gr.Dropdown(
37
+ choices=['en', 'fr', 'es', 'de', 'it', 'ro', 'tr', 'br', 'ru'],
38
+ label='Choose a language',
39
+ value='en'
40
+ )
41
 
42
  text = gr.Textbox(label="Input text", placeholder="Enter your text and then click the 'Text-To-Speech' button or press Enter.")
43
  btn = gr.Button("Text-To-Speech")
44
  output_audio = gr.Audio(label="Speech Output")
45
 
46
+ text.submit(fn=tts, inputs=[text, model, voice, language, api_key], outputs=output_audio, api_name="tts_enter_key", concurrency_limit=None)
47
+ btn.click(fn=tts, inputs=[text, model, voice, language, api_key], outputs=output_audio, api_name="tts_button", concurrency_limit=None)
48
 
49
+ demo.launch()