You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
824 B
31 lines
824 B
11 months ago
|
import ffmpeg
|
||
|
import tempfile
|
||
|
from openai import OpenAI
|
||
|
import os
|
||
|
import subprocess
|
||
|
import tempfile
|
||
|
|
||
|
client = OpenAI()
|
||
|
|
||
|
class Tts:
|
||
|
def __init__(self, config):
|
||
|
pass
|
||
|
|
||
|
def tts(self, text):
|
||
|
response = client.audio.speech.create(
|
||
|
model="tts-1",
|
||
|
voice="alloy",
|
||
|
input=text,
|
||
|
response_format="opus"
|
||
|
)
|
||
|
with tempfile.NamedTemporaryFile(suffix=".opus", delete=False) as temp_file:
|
||
|
response.stream_to_file(temp_file.name)
|
||
|
|
||
|
# TODO: hack to format audio correctly for device
|
||
|
outfile = tempfile.gettempdir() + "/" + "raw.dat"
|
||
11 months ago
|
ffmpeg.input(temp_file.name).output(outfile, f="s16le", ar="16000", ac="1", loglevel='panic').run()
|
||
11 months ago
|
|
||
|
return outfile
|
||
|
|
||
|
|