Spaces:
Sleeping
Sleeping
File size: 690 Bytes
9da994b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
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)
|