Jerich commited on
Commit
bf59705
·
verified ·
1 Parent(s): e79c9c5

Fix TTS error by updating save_pcm_to_wav to handle 16-bit audio samples correctly using NumPy tobytes()

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -69,13 +69,16 @@ NLLB_LANGUAGE_CODES = {
69
 
70
  # Function to save PCM data as a WAV file
71
  def save_pcm_to_wav(pcm_data: list, sample_rate: int, output_path: str):
 
 
 
72
  with wave.open(output_path, 'wb') as wav_file:
73
  # Set WAV parameters: 1 channel (mono), 2 bytes per sample (16-bit), sample rate
74
  wav_file.setnchannels(1)
75
  wav_file.setsampwidth(2) # 16-bit audio
76
  wav_file.setframerate(sample_rate)
77
- # Convert PCM data (list of integers) to bytes
78
- wav_file.writeframes(bytes(pcm_data))
79
 
80
  # Function to clean up old audio files
81
  def cleanup_old_audio_files():
 
69
 
70
  # Function to save PCM data as a WAV file
71
  def save_pcm_to_wav(pcm_data: list, sample_rate: int, output_path: str):
72
+ # Convert pcm_data to a NumPy array of 16-bit integers
73
+ pcm_array = np.array(pcm_data, dtype=np.int16)
74
+
75
  with wave.open(output_path, 'wb') as wav_file:
76
  # Set WAV parameters: 1 channel (mono), 2 bytes per sample (16-bit), sample rate
77
  wav_file.setnchannels(1)
78
  wav_file.setsampwidth(2) # 16-bit audio
79
  wav_file.setframerate(sample_rate)
80
+ # Write the 16-bit PCM data as bytes (little-endian)
81
+ wav_file.writeframes(pcm_array.tobytes())
82
 
83
  # Function to clean up old audio files
84
  def cleanup_old_audio_files():