SyntaxError: Non-ASCII character

ldompeling at casema.nl ldompeling at casema.nl
Sun Jul 17 08:01:21 EDT 2016


Op zondag 17 juli 2016 11:19:32 UTC+2 schreef ldomp... at casema.nl:
> 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()

I installed python 3.4 and set my python path to PYTONPATH:/usr/bin/python3.4

When I try to import pyaudio then I get this error:
Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyaudio
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'pyaudio'

Do I have to set a path also for to find the modules



More information about the Python-list mailing list