Home > Software engineering >  Simpleaudio cuts some wav files at the end
Simpleaudio cuts some wav files at the end

Time:02-10

I'm using simpleaudio to play speech wav files from internet URLs. Please see my script below. The problem is that for most wav files it works well but for some speech files it is stopped before reaching the end. In the example below you can see that the last word is only played half.

Why is that the case?

import requests
import simpleaudio

sample_rate = 24000
num_channels = 1
bytes_per_sample = 2

total = sample_rate * num_channels * bytes_per_sample
content = requests.get("https://v1.api.audio/url/38ede/default__$3ct10n~1of1.wav").content

blocks = len(content) // total
content = content[:total * blocks]

wave = simpleaudio.WaveObject(audio_data=content,
                              sample_rate=sample_rate,
                              num_channels=num_channels,
                              bytes_per_sample=bytes_per_sample)
control = wave.play()
control.wait_done()

CodePudding user response:

  •  Tags:  
  • Related