ISTNetworks commited on
Commit
c11c178
·
verified ·
1 Parent(s): 799e5fe

Fix inference.py - properly write WAV files with audio data

Browse files
Files changed (1) hide show
  1. inference.py +10 -3
inference.py CHANGED
@@ -50,9 +50,16 @@ def synthesize_text(text, model_path, output_path, config_path=None):
50
  # Synthesize
51
  print(f"Synthesizing: {text}")
52
  try:
53
- with open(output_path, 'wb') as f:
54
- # Write WAV header
55
- voice.synthesize(text, f)
 
 
 
 
 
 
 
56
  print(f"✓ Audio saved to: {output_path}")
57
  except Exception as e:
58
  print(f"Error during synthesis: {e}")
 
50
  # Synthesize
51
  print(f"Synthesizing: {text}")
52
  try:
53
+ import wave
54
+
55
+ with wave.open(output_path, 'wb') as wav_file:
56
+ wav_file.setframerate(voice.config.sample_rate)
57
+ wav_file.setsampwidth(2) # 16-bit
58
+ wav_file.setnchannels(1) # Mono
59
+
60
+ for audio_chunk in voice.synthesize(text):
61
+ wav_file.writeframes(audio_chunk.audio_int16_bytes)
62
+
63
  print(f"✓ Audio saved to: {output_path}")
64
  except Exception as e:
65
  print(f"Error during synthesis: {e}")