Spaces:
Runtime error
Runtime error
File size: 617 Bytes
446c342 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import io
from openai import OpenAI
from pydub import AudioSegment
from .tts_utils import mix_background_music
def tts(openai_api_key, txt, model, voice, 背景音乐, TTS_up, bg_up):
try:
client = OpenAI(api_key=openai_api_key)
response = client.audio.speech.create(
model=model,
voice=voice,
input=txt
)
original_audio = AudioSegment.from_file(io.BytesIO(response.content), format="mp3")
return None, *mix_background_music(original_audio, 背景音乐, TTS_up, bg_up)
except Exception as e:
return str(e), None, None
|