I copy this script from the magpi but when I run this script I get this error: SyntaxError: Non-ASCII character '\xe2' in file sound.py on line 32, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
Below is the eamplescript. What is wrong with this script. # You need to import the pyaudio module import pyaudio # First, we will listen # We need to set some parameters # Buffer chunk size in bytes CHUNK = 1024 # The audio format FORMAT = pyaudio.paInt16 # The number of channels to record on CHANNELS = 2 # The sample rate, 44.1KHz RATE = 44100 # The number of seconds to record for RECORD_SECS = 5 # Next, we create a PyAudio object p = pyaudio.PyAudio() # We need a stream to record from stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=TRUE, frames_per_buffer=CHUNK) # We can now record into a temporary buffer frames = [] for i in range(0, int(RATE / CHUNK * RECORD_SECS)): data = stream.read(CHUNK) frames.append(data) # We can now shut everything down stream.stop_stream() stream.close() p.terminate() # If we want to play a wave file, we will need the wave module import wave # We can open it, give a filename wf = wave.open(“test.wav”, “rb”) # We need a new PyAudio object p = pyaudio.PyAudio() # We will open a stream, using the settings from the wave file stream = p.open(format=p.get_format_from_width(wf.getsampwidth()), channels=wf.getnchannels(), rate=wf.getframerate(), output=True) # We can now read from the file and play it out data = wf.readframes(CHUNK) while data != ‘’: stream.write(data) data = wf.readframes(CHUNK) # Don’t forget to shut everything down again stream.stop_stream() stream.close() p.terminate() -- https://mail.python.org/mailman/listinfo/python-list