Skip to content

Instantly share code, notes, and snippets.

@forslund
Created December 10, 2020 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forslund/ee5595dee2c2fc20a5609fd300a6b3c4 to your computer and use it in GitHub Desktop.
Save forslund/ee5595dee2c2fc20a5609fd300a6b3c4 to your computer and use it in GitHub Desktop.
import time
import wave
import speech_recognition as sr
frames = []
microphone = sr.Microphone()
with microphone as source:
start = time.time()
while time.time() < start + 5:
data = source.stream.read(source.CHUNK)
frames.append(data)
waveFile = wave.open('test.wav', 'wb')
waveFile.setnchannels(1)
waveFile.setsampwidth(source.SAMPLE_WIDTH)
waveFile.setframerate(source.SAMPLE_RATE)
waveFile.writeframes(b''.join(frames))
waveFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment