Spaces:
Sleeping
Sleeping
| import openai | |
| import gradio as gr | |
| import os | |
| # Set your OpenAI API key | |
| openai.api_key = os.getenv("OPENAI_API_KEY") # Read from environment variable | |
| def text_to_speech(text): | |
| response = openai.audio.speech.create( | |
| model="tts-1", # or "tts-1-hd" | |
| voice="nova", # options: "nova", "shimmer", etc | |
| input=text | |
| ) | |
| filename = "output.mp3" | |
| with open(filename, "wb") as f: | |
| f.write(response.content) | |
| return filename | |
| iface = gr.Interface( | |
| fn=text_to_speech, | |
| inputs=gr.Textbox(lines=2, placeholder="Enter text to convert to speech..."), | |
| outputs=gr.Audio(type="filepath"), | |
| title="Text to Speech with OpenAI", | |
| description="Enter text and get the spoken audio!", | |
| ) | |
| iface.launch() | |