我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用pyaudio.paComplete()。
def callback(self, in_data, count, time_info, status): if self.pos + count > self.range[1]: output = self.signal[self.pos:self.range[1], :] status = pa.paComplete if self.stop_func: self.stop_func() else: output = self.signal[self.pos:self.pos + count, :] status = pa.paContinue self.pos += count return (output.flatten().astype(np.float32).tostring(), status)
def callback(self, in_data, count, time_info, status): import numpy as np input = np.fromstring(in_data, dtype=np.float32).astype( types.float_) input_frames = len(input) / self.num_channels input = np.reshape(input, (input_frames, self.num_channels)) np.vstack((self.signal,input)) if (self.pos + count) >= self.total_frames: status = pa.paComplete print("recording done") if self.stop_func: self.stop_func() else: status = pa.paContinue self.pos += count return (None, status)
def wav_callback(self, in_data, frame_count, time_info, status): data = self.wav.readframes(frame_count) flag = pyaudio.paContinue if self.wav.getnframes() == self.wav.tell(): data = data.ljust(frame_count * self.wav.getsampwidth() * self.wav.getnchannels(), '\x00') # flag = pyaudio.paComplete self.event.set() return data, flag
def raw_callback(self, in_data, frame_count, time_info, status): size = frame_count * self.width * self.channels data = self.raw[:size] self.raw = self.raw[size:] flag = pyaudio.paContinue if not len(self.raw): data = data.ljust(frame_count * self.width * self.channels, '\x00') # flag = pyaudio.paComplete self.event.set() return data, flag
def _stream_callback(self, in_data, frame_count, time_info, status_flags): chunk = AudioChunk(start_time=time_info['input_buffer_adc_time'], audio=in_data, freq=self._rate, width=2) self._stream_queue.sync_q.put(chunk) retflag = pyaudio.paContinue if self.running else pyaudio.paComplete return (None, retflag)
def _callback(self, in_data, frame_count, time_info, status): """ Callback function for continuous_record Checks global var recording If true, put frames into the queue - another thread will pop from the queue and write to disk If false, shut down the recorder (we don't want silence or sudden time shifts in one recording file) """ if self._recording: self._frames.put(in_data) callback_flag = pyaudio.paContinue else: callback_flag = pyaudio.paComplete return in_data, callback_flag
def get_frame(self, in_data, frame_count, time_info, status): """ Callback function for the pyaudio stream. Don't use directly. """ while self.keep_listening: try: frame = self.queue.get(False, timeout=queue_timeout) return (frame, pyaudio.paContinue) except Empty: pass return (None, pyaudio.paComplete)
def _apiai_stt(self): from math import log import audioop import pyaudio import time resampler = apiai.Resampler(source_samplerate=settings['RATE']) request = self.ai.voice_request() vad = apiai.VAD() def callback(in_data, frame_count): frames, data = resampler.resample(in_data, frame_count) if settings.show_decibels: decibel = 20 * log(audioop.rms(data, 2) + 1, 10) click.echo(decibel) state = vad.processFrame(frames) request.send(data) state_signal = pyaudio.paContinue if state == 1 else pyaudio.paComplete return in_data, state_signal p = pyaudio.PyAudio() stream = p.open(format=pyaudio.paInt32, input=True, output=False, stream_callback=callback, channels=settings['CHANNELS'], rate=settings['RATE'], frames_per_buffer=settings['CHUNK']) stream.start_stream() click.echo("Speak!") while stream.is_active(): time.sleep(0.1) stream.stop_stream() stream.close() p.terminate()