I’m having trouble using the answer from How can I play wav binary data with pyaudio? as quoted below:
import pyaudio
import wave
import io
# response.audio_content is a byte string
with wave.open(io.BytesIO(response.audio_content), 'rb') as f:
width = f.getsampwidth()
channels = f.getnchannels()
rate = f.getframerate()
pa = pyaudio.PyAudio()
pa_stream = pa.open(
format=pyaudio.get_format_from_width(width),
channels=channels,
rate=rate,
output=True
)
pa_stream.write(response.audio_content)
-
I get the error “NameError: global name ‘response’ is not defined”.
BTW, I’m stuck on Python 2.6 because of a bigger package (EventGhost) which uses that version of Python.
I’ve tried importing response from pyaudio, wave, and io. But no joy there. I’m starting to think this newbee python user just doesn’t have a grasp of the basics. Any help would be appreciated.