Spaces:
Sleeping
Sleeping
from pathlib import Path | |
from openai import OpenAI | |
import os | |
client = OpenAI() | |
def text_to_speech(client: OpenAI, input: str) -> str: | |
generated_speech_path = "data/generated_speech" | |
n = len(os.listdir(generated_speech_path)) | |
response = client.audio.speech.create( | |
model="tts-1", voice="nova", response_format="wav", input=input, speed=1.0 | |
) | |
output_path = os.path.join(generated_speech_path, str(n)) + ".wav" | |
response.stream_to_file(output_path) | |
return output_path | |
if __name__ == "__main__": | |
input = "Ciao Pinocchio, è vero che la neve è calda? Che ne pensi?" | |
openai_client = OpenAI() | |
text_to_speech(client=openai_client, input=input) | |