1

I would like to know how I can play mp3 raw audio data (retrieved from Ivona text to speech API) without writing it to a file.

Does I have to convert it to wav and use pyaudio?

linusg
  • 6,289
  • 4
  • 28
  • 78

1 Answers1

0

Here's a way to do it:

from urllib.request import urlopen
import pyaudio

pyaud = pyaudio.PyAudio()
srate=44100
stream = pyaud.open(format = pyaud.get_format_from_width(1),
                channels = 1,
                rate = srate,
                output = True)


url = ... # Assuming you retrive audio data from an URL
u = urlopen(url)
data = u.read(8192)

while data:
    stream.write(data)
    data = u.read(8192)

For reference, see How to play mp3 from URL.

Hope this helps!

Community
  • 1
  • 1
linusg
  • 6,289
  • 4
  • 28
  • 78