use default sample rate instead of forcing 44100

The 64 bit built of portaudio on OSX seems to generate a wav
file that says it's 44100 but is actually the default rate, leading
to samples playing too fast or slow.
This commit is contained in:
Damien Elmes 2014-04-18 04:17:05 +09:00
parent 88b0a36610
commit 89c9af7445

View file

@ -204,12 +204,12 @@ addHook("unloadProfile", stopMplayer)
########################################################################## ##########################################################################
try: try:
import pyaudio import pyaudio
import wave import wave
PYAU_FORMAT = pyaudio.paInt16 PYAU_FORMAT = pyaudio.paInt16
PYAU_CHANNELS = 1 PYAU_CHANNELS = 1
PYAU_RATE = 44100
PYAU_INPUT_INDEX = None PYAU_INPUT_INDEX = None
except: except:
pass pass
@ -244,12 +244,16 @@ class PyAudioThreadedRecorder(threading.Thread):
except NameError: except NameError:
raise Exception( raise Exception(
"Pyaudio not installed (recording not supported on OSX10.3)") "Pyaudio not installed (recording not supported on OSX10.3)")
rate = int(p.get_default_input_device_info()['defaultSampleRate'])
stream = p.open(format=PYAU_FORMAT, stream = p.open(format=PYAU_FORMAT,
channels=PYAU_CHANNELS, channels=PYAU_CHANNELS,
rate=PYAU_RATE, rate=rate,
input=True, input=True,
input_device_index=PYAU_INPUT_INDEX, input_device_index=PYAU_INPUT_INDEX,
frames_per_buffer=chunk) frames_per_buffer=chunk)
all = [] all = []
while not self.finish: while not self.finish:
try: try:
@ -267,7 +271,7 @@ class PyAudioThreadedRecorder(threading.Thread):
wf = wave.open(processingSrc, 'wb') wf = wave.open(processingSrc, 'wb')
wf.setnchannels(PYAU_CHANNELS) wf.setnchannels(PYAU_CHANNELS)
wf.setsampwidth(p.get_sample_size(PYAU_FORMAT)) wf.setsampwidth(p.get_sample_size(PYAU_FORMAT))
wf.setframerate(PYAU_RATE) wf.setframerate(rate)
wf.writeframes(data) wf.writeframes(data)
wf.close() wf.close()