File size: 396 Bytes
2da4544
 
c7fc3b6
2da4544
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from pathlib import Path
from config import client

def text_to_speech(text: str, voice: str = "Aaliyah-PlayAI", fmt: str = "wav"):
    speech_path = Path("audio/temp/output." + fmt)

    response = client.audio.speech.create(
        model="playai-tts",
        voice=voice,
        response_format=fmt,
        input=text,
    )

    response.stream_to_file(speech_path)
    return speech_path