Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyaudio
- import wave
- import sys
- CHUNK = 1024
- FORMAT = pyaudio.paInt16
- CHANNELS = 1
- RATE = 16000
- RECORD_SECONDS = int(sys.argv[2])
- WAVE_OUTPUT_FILENAME = sys.argv[1]
- #RECORD_SECONDS = 7
- #WAVE_OUTPUT_FILENAME = "output.wav"
- print RECORD_SECONDS
- print WAVE_OUTPUT_FILENAME
- p = pyaudio.PyAudio()
- stream = p.open(format=FORMAT,
- channels=CHANNELS,
- rate=RATE,
- input=True,
- frames_per_buffer=CHUNK)
- print("* recording")
- frames = []
- for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
- data = stream.read(CHUNK)
- frames.append(data)
- print("* done recording")
- stream.stop_stream()
- stream.close()
- p.terminate()
- wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
- wf.setnchannels(CHANNELS)
- wf.setsampwidth(p.get_sample_size(FORMAT))
- wf.setframerate(RATE)
- wf.writeframes(b''.join(frames))
- wf.close()
- Expression 'PaAlsaStream_Configure( stream, inputParameters, outputParameters, sampleRate, framesPerBuffer, &inputLatency, &outputLatency, &hostBufferSizeMode )'
- failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2843
- Traceback (most recent call last):
- File "rec.py", line 26, in <module>
- frames_per_buffer=CHUNK)
- File "/usr/lib/python2.7/dist-packages/pyaudio.py", line 750, in open
- stream = Stream(self, *args, **kwargs)
- File "/usr/lib/python2.7/dist-packages/pyaudio.py", line 441, in __init__
- self._stream = pa.open(**arguments)
- IOError: [Errno -9997] Invalid sample rate
Add Comment
Please, Sign In to add comment