teachingAssistant / utils /tts_dummy.py
Michael Hu
fix runtime dia model issue
2d176f4
raw
history blame contribute delete
769 Bytes
def generate_speech(text: str, language: str = "zh") -> str:
"""Public interface for TTS generation"""
import os
import numpy as np
import soundfile as sf
import time
# Create output directory if it doesn't exist
output_dir = "temp/outputs"
os.makedirs(output_dir, exist_ok=True)
# Generate a unique filename
timestamp = int(time.time())
output_path = f"{output_dir}/dummy_{timestamp}.wav"
# Generate a simple sine wave as dummy audio
sample_rate = 24000
duration = 2.0 # seconds
t = np.linspace(0, duration, int(sample_rate * duration), False)
tone = np.sin(2 * np.pi * 440 * t) * 0.3
# Save the audio file
sf.write(output_path, tone, sample_rate)
return output_path