Spaces:
Runtime error
Runtime error
import os | |
import openai | |
from openai import OpenAI | |
from config import OPENAI_API_KEY | |
# import shutil | |
def generate_speech(path, outfile, voice, text, speed): | |
# Initialize OpenAI TTS API | |
openai.api_key = OPENAI_API_KEY | |
# Generate speech using OpenAI's TTS | |
try: | |
client = OpenAI() | |
response = client.audio.speech.create( | |
model='tts-1-hd', | |
voice=voice, | |
input=text, | |
speed=speed | |
# Add other parameters as needed | |
) | |
print(f"the response content: {response}") | |
except Exception as e: | |
print(f"Error during speech generation: {e}") | |
return | |
# Stream the audio to a file | |
response.stream_to_file('voices\output.mp3') | |
# shutil.copy('voices\output.mp3', os.path.abspath(path)) | |
print("Speech generation completed.") |