|
import numpy as np |
|
import torchaudio |
|
import logging |
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG) |
|
|
|
def synthesize_speech(text): |
|
try: |
|
|
|
sr = 16000 |
|
t = np.linspace(0, 1, sr) |
|
waveform = 0.5 * np.sin(2 * np.pi * 440 * t).astype(np.float32) |
|
|
|
|
|
file_path = "/tmp/output.wav" |
|
torchaudio.save(file_path, torch.tensor(waveform).unsqueeze(0), sr) |
|
logging.info(f"Test audio file saved successfully at {file_path}.") |
|
return file_path |
|
except Exception as e: |
|
logging.error(f"Error during test audio generation: {e}") |
|
return None |
|
|