daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pyaudio
  2. import wave
  3. import sys
  4.  
  5. CHUNK = 1024
  6. FORMAT = pyaudio.paInt16
  7. CHANNELS = 1
  8. RATE = 16000
  9. RECORD_SECONDS = int(sys.argv[2])
  10. WAVE_OUTPUT_FILENAME = sys.argv[1]
  11.  
  12. #RECORD_SECONDS = 7
  13. #WAVE_OUTPUT_FILENAME = "output.wav"
  14. print RECORD_SECONDS
  15. print WAVE_OUTPUT_FILENAME
  16.  
  17. p = pyaudio.PyAudio()
  18.  
  19. stream = p.open(format=FORMAT,
  20.                 channels=CHANNELS,
  21.                 rate=RATE,
  22.                 input=True,
  23.                 frames_per_buffer=CHUNK)
  24.  
  25. print("* recording")
  26.  
  27. frames = []
  28.  
  29. for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
  30.     data = stream.read(CHUNK)
  31.     frames.append(data)
  32.  
  33. print("* done recording")
  34.  
  35. stream.stop_stream()
  36. stream.close()
  37. p.terminate()
  38.  
  39. wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
  40. wf.setnchannels(CHANNELS)
  41. wf.setsampwidth(p.get_sample_size(FORMAT))
  42. wf.setframerate(RATE)
  43. wf.writeframes(b''.join(frames))
  44. wf.close()
  45.    
  46. Expression 'PaAlsaStream_Configure( stream, inputParameters, outputParameters, sampleRate, framesPerBuffer, &inputLatency, &outputLatency, &hostBufferSizeMode )'
  47. failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2843
  48. Traceback (most recent call last):
  49.   File "rec.py", line 26, in <module>
  50.     frames_per_buffer=CHUNK)
  51.   File "/usr/lib/python2.7/dist-packages/pyaudio.py", line 750, in open
  52.     stream = Stream(self, *args, **kwargs)
  53.   File "/usr/lib/python2.7/dist-packages/pyaudio.py", line 441, in __init__
  54.     self._stream = pa.open(**arguments)
  55. IOError: [Errno -9997] Invalid sample rate
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top