deekshitha9876's picture
Create app.py
1d8366d verified
raw
history blame
760 Bytes
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()