Skip to content

Commit

Permalink
use mplayer to convert usb audio bitrate
Browse files Browse the repository at this point in the history
  • Loading branch information
jitto committed Mar 26, 2016
1 parent 0604ac3 commit 04230bf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import json
import re
from memcache import Client

import wave


recorded = False
Expand Down Expand Up @@ -113,14 +113,19 @@ def alexa():
if val != last:
last = val
if val == '1' and recorded == True:
with open('recording.wav', 'wb') as rf:
rf.write(audio)
wf = wave.open('record.wav', 'wb')
wf.setnchannels(1)
wf.setsampwidth(2)
wf.setframerate(44100)
wf.writeframes(audio)
wf.close()
os.system('mplayer -ao pcm:fast:waveheader:file=recording.wav -srate 16000 -vo null -vc null record.wav')
inp = None
alexa()
elif val == '0':
inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL)
inp.setchannels(1)
inp.setrate(16000)
inp.setrate(44100)
inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
inp.setperiodsize(500)
audio = b""
Expand Down

0 comments on commit 04230bf

Please sign in to comment.