File size: 769 Bytes
a602e5e
 
2d176f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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