ghostai1 commited on
Commit
758bfe8
·
verified ·
1 Parent(s): 866f7ce

Update barks.py

Browse files
Files changed (1) hide show
  1. barks.py +4 -2
barks.py CHANGED
@@ -303,9 +303,11 @@ def generate_vocals(vocal_prompt: str, total_duration: int):
303
 
304
  # Convert to numpy and create AudioSegment
305
  vocal_array = vocal_array.cpu().numpy().squeeze()
306
- sample_rate = bark_model.config.sampling_rate
307
  temp_vocal_path = "temp_vocal.wav"
308
- torchaudio.save(temp_vocal_path, torch.tensor(vocal_array).unsqueeze(0), sample_rate)
 
 
309
  vocal_segment = AudioSegment.from_wav(temp_vocal_path)
310
  os.remove(temp_vocal_path)
311
 
 
303
 
304
  # Convert to numpy and create AudioSegment
305
  vocal_array = vocal_array.cpu().numpy().squeeze()
306
+ sample_rate = 24000 # Default sample rate for suno/bark-small
307
  temp_vocal_path = "temp_vocal.wav"
308
+ # Convert tensor to float32 for torchaudio.save compatibility
309
+ vocal_tensor = torch.tensor(vocal_array, dtype=torch.float32).unsqueeze(0)
310
+ torchaudio.save(temp_vocal_path, vocal_tensor, sample_rate)
311
  vocal_segment = AudioSegment.from_wav(temp_vocal_path)
312
  os.remove(temp_vocal_path)
313