def start_rec(self): if platform == 'android': '''self.MediaRecorder = autoclass('android.media.MediaRecorder') self.AudioSource = autoclass('android.media.MediaRecorder$AudioSource') self.AudioFormat = autoclass('android.media.AudioFormat') self.AudioRecord = autoclass('android.media.AudioRecord') # define our system self.SampleRate = 8000 self.ChannelConfig = self.AudioFormat.CHANNEL_IN_MONO self.AudioEncoding = self.AudioFormat.ENCODING_PCM_16BIT #self.BufferSize = self.AudioRecord.getMinBufferSize(self.SampleRate, self.ChannelConfig, self.AudioEncoding)*8 #if self.BufferSize < 16384: # self.BufferSize = 16384''' self.BufferSize = 16384 self.mobile_input_stream = get_input( callback=record_callback_mobile, source='default', buffersize=self.BufferSize, rate=8000) self.mobile_input_stream.start() Clock.schedule_interval(self.readbuffer, 1 / float(10)) elif platform == 'ios': self.mobile_input_stream = get_input( callback=record_callback_mobile, source='default', rate=8000) self.mobile_input_stream.start() Clock.schedule_interval(self.readbuffer, 1 / float(60)) else: self.input_stream = sd.InputStream(samplerate=8000, channels=1, dtype='int16'\ , callback=record_callback) self.input_stream.start()
def keep_record(self, stop_flag, channels=1, encoding=16, rate=8000): def mic_callback(buf): print "got data", len(buf) frames.append(buf) frames = [] # Need to set buffersize print "keep_record: Prepare..." mic = get_input(callback=mic_callback, channels=channels, encoding=encoding, rate=rate, buffersize=1024) print "keep_record: Starting..." mic.start() print "keep_record: Started..." while not stop_flag["flag"]: # Read the internal queue and dispatch the data through the callback mic.poll() mic.stop() # Remove the prepending Inpulse voice str_bin_data = ''.join(frames)[200:] data = [int(binascii.b2a_hex(i), 16) for i in str_bin_data] return (data, str_bin_data)
def on_start(self): self._frames = [] mic = get_input(callback=self.mic_callback) mic.start() time.sleep(10) mic.stop() wf = wave.open("test.wav", 'wb') wf.setnchannels(mic.channels) wf.setsampwidth(2) wf.setframerate(mic.rate) wf.writeframes(b''.join(self.frames)) wf.close() symbols = 'Recording completed!' #for m in dir(sd): #symbols += m + '\n' self.label.text = symbols
def keep_record(self, stop_flag, channels=1, encoding=16, rate=8000): def mic_callback(buf): print "got data", len(buf) frames.append(buf) frames = [] # Need to set buffersize print "keep_record: Prepare..." mic = get_input(callback=mic_callback, channels=channels, encoding=encoding, rate=rate, buffersize = 1024) print "keep_record: Starting..." mic.start() print "keep_record: Started..." while not stop_flag["flag"]: # Read the internal queue and dispatch the data through the callback mic.poll() mic.stop() # Remove the prepending Inpulse voice str_bin_data = ''.join(frames)[200:] data = [int(binascii.b2a_hex(i), 16) for i in str_bin_data] return (data, str_bin_data)
def record(): mic = get_input(callback=callback_mic) mic.start() time.sleep(5) mic.stop()
import time import wave from audiostream import get_input frames = [] def mic_callback(buf): print 'got', len(buf) frames.append(buf) # get the default audio input (mic on most cases) mic = get_input(callback=mic_callback) mic.start() time.sleep(5) mic.stop() wf = wave.open("test.wav", 'wb') wf.setnchannels(mic.channels) wf.setsampwidth(2) wf.setframerate(mic.rate) wf.writeframes(b''.join(frames)) wf.close()
import time import wave from audiostream import get_input frames = [] def mic_callback(buf): print('got', len(buf)) frames.append(buf) # get the default audio input (mic on most cases) mic = get_input(callback=mic_callback) mic.start() time.sleep(5) mic.stop() wf = wave.open("test.wav", 'wb') wf.setnchannels(mic.channels) wf.setsampwidth(2) wf.setframerate(mic.rate) wf.writeframes(b''.join(frames)) wf.close()