Python pyaudio 模块,paComplete() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用pyaudio.paComplete()

项目:untwist    作者:IoSR-Surrey    | 项目源码 | 文件源码
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)
项目:untwist    作者:IoSR-Surrey    | 项目源码 | 文件源码
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)
项目:IRLearning_ReSpeaker    作者:Lee-Kevin    | 项目源码 | 文件源码
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
项目:IRLearning_ReSpeaker    作者:Lee-Kevin    | 项目源码 | 文件源码
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
项目:streamtotext    作者:ibm-dev    | 项目源码 | 文件源码
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)
项目:high-quality-chat    作者:b6938236    | 项目源码 | 文件源码
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
项目:python-mediadecoder    作者:dschreij    | 项目源码 | 文件源码
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)
项目:Friday    作者:Zenohm    | 项目源码 | 文件源码
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()