当前位置: 首页>>代码示例>>Python>>正文


Python pyaudio.paContinue方法代码示例

本文整理汇总了Python中pyaudio.paContinue方法的典型用法代码示例。如果您正苦于以下问题:Python pyaudio.paContinue方法的具体用法?Python pyaudio.paContinue怎么用?Python pyaudio.paContinue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyaudio的用法示例。


在下文中一共展示了pyaudio.paContinue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: callback

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def callback(in_data, frame_count, time_info, status):
    """Audio recorder's stream callback function."""
    global data_list, is_recording, enable_trigger_record
    if is_recording:
        data_list.append(in_data)
        enable_trigger_record = False
    elif len(data_list) > 0:
        # Connect to server and send data
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect((args.host_ip, args.host_port))
        sent = ''.join(data_list)
        sock.sendall(struct.pack('>i', len(sent)) + sent)
        print('Speech[length=%d] Sent.' % len(sent))
        # Receive data from the server and shut down
        received = sock.recv(1024)
        print "Recognition Results: {}".format(received)
        sock.close()
        data_list = []
    enable_trigger_record = True
    return (in_data, pyaudio.paContinue) 
开发者ID:Pelhans,项目名称:ZASR_tensorflow,代码行数:22,代码来源:demo_client.py

示例2: __init__

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def __init__(self, callback=None, buffer_s=0, flush_queue=True):
        def proxy_callback(in_data, frame_count, time_info, status):
            callback(in_data)
            return (None, pyaudio.paContinue)
        if callback is None: callback = lambda in_data: self.buffer_queue.put(in_data, block=False)
        self.sample_rate = self.RATE
        self.flush_queue = flush_queue
        self.buffer_queue = queue.Queue(maxsize=(buffer_s * 1000 // self.block_duration_ms))
        self.pa = pyaudio.PyAudio()
        self.stream = self.pa.open(format=self.FORMAT,
                                   channels=self.CHANNELS,
                                   rate=self.sample_rate,
                                   input=True,
                                   frames_per_buffer=self.block_size,
                                   stream_callback=proxy_callback)
        self.stream.start_stream()
        self.active = True 
开发者ID:daanzu,项目名称:deepspeech-websocket-server,代码行数:19,代码来源:client.py

示例3: _on_audio

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def _on_audio(self, in_data, frame_count, time_info, status):
        data_ok = (in_data, pyaudio.paContinue)
        self.last_data = in_data
        self._audio_buf.append(in_data)
        if len(self._audio_buf) != 16:
            return data_ok
        audio_data = base64.b64encode(zlib.compress(b"".join(self._audio_buf)))
        self._audio_buf = []
        response = requests.post("{}/listen".format(self.endpoint), json=dict(wav_data=audio_data.decode(), method="all_label"))
        response = json.loads(response.content.decode())
        if not response:
            return data_ok
        max_key = max(response.items(), key=lambda x: x[1])[0]
        for key in response:
            p = response[key]
            if p < 0.5 and key != "__unknown__":
                continue
            key = key.replace("_", "")
            try:
                Indicator.indicators[labels.index(key)].highlight(1.)
            except ValueError:
                continue
        return data_ok 
开发者ID:castorini,项目名称:honk,代码行数:25,代码来源:speech_demo.py

示例4: _on_audio

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def _on_audio(self, in_data, frame_count, time_info, status):
        data_ok = (in_data, pyaudio.paContinue)
        self.last_data = in_data
        self._audio_buf.append(in_data)
        if len(self._audio_buf) != 16:
            return data_ok
        audio_data = base64.b64encode(zlib.compress(b"".join(self._audio_buf)))
        self._audio_buf = []
        response = requests.post("{}/listen".format(self.endpoint), json=dict(wav_data=audio_data.decode(), method="all_label"))
        response = json.loads(response.content.decode())
        if not response:
            return data_ok
        max_key = max(response.items(), key=lambda x: x[1])[0]
        for key in response:
            p = response[key]
            if p < 0.5 and key != "__unknown__":
                continue
            key = key.replace("_", "")
            print(key)
            self.words += [ key ]
        return data_ok 
开发者ID:castorini,项目名称:honk,代码行数:23,代码来源:speech_demo_tk.py

示例5: __init__

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def __init__(self, data, fmt):

        if fmt.formatTag != RIFF.WAVE_fmt_.WAVE_FORMAT_PCM:
            raise Exception()

        if fmt.samplesPerSec < 1000 or fmt.samplesPerSec > 192000:
            data, fmt = wav_tools.wav_resample_preview(data, fmt, 1000, 192000)
        self.data = data
        self.fmt = fmt
        self._offset = 0

        def callback(indata, frames, time, status):
            n_bytes=frames*fmt.blockAlign
            to_read=min(n_bytes, len(self.data) - self._offset)
            outdata = self.data[self._offset:self._offset+to_read]
            self._offset += to_read
            return (outdata,pa.paContinue)

        self.stream = audio.open(format=pa.paInt16, channels=fmt.channels, rate=fmt.samplesPerSec, output=True, stream_callback=callback) 
开发者ID:JonathanTaquet,项目名称:Oe2sSLE,代码行数:21,代码来源:audio.py

示例6: callback

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def callback(in_data, frame_count, time_info, status):
    data = wf.readframes(frame_count)
    return (data, pyaudio.paContinue) 
开发者ID:Akagi201,项目名称:learning-python,代码行数:5,代码来源:play_callback.py

示例7: callback

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def callback(in_data, frame_count, time_info, status):
    return (in_data, pyaudio.paContinue) 
开发者ID:Akagi201,项目名称:learning-python,代码行数:4,代码来源:wire_callback.py

示例8: _enqueue_raw_audio

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def _enqueue_raw_audio(self, in_data, *_):  # unused args to match expected
    try:
      self._raw_audio_queue.put((in_data, time.time()), block=False)
      return None, pyaudio.paContinue
    except queue.Full:
      error_message = 'Raw audio buffer full.'
      logging.error(error_message)
      raise AudioTimeoutError(error_message) 
开发者ID:magenta,项目名称:magenta,代码行数:10,代码来源:audio_recorder.py

示例9: listen

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def listen(device='default', channels=2, frames_per_buffer=1024, rate=44100):
    global audio_data
    audio_data = np.zeros([channels, frames_per_buffer])

    pa = pyaudio.PyAudio()
    devices = get_devices(pa)
    # print(devices)
    input_device = devices[device]

    def stream_cb(in_data, frame_count, time_info, status):
        data = np.fromstring(in_data, dtype=np.float32)
        data = np.reshape(data, (frame_count, channels))
        data = [data[:, i]
                for i in range(channels)]

        audio_data[:, :] = data

        return (in_data, pyaudio.paContinue)

    stream = pa.open(format=pyaudio.paFloat32,
                     channels=channels,
                     rate=rate,
                     frames_per_buffer=frames_per_buffer,
                     input=True,
                     input_device_index=input_device,
                     stream_callback=stream_cb)

    def idle():
        stream.start_stream()

        try:
            while True:
                sleep(1)
        finally:
            stream.stop_stream()
            stream.close()
            pa.terminate()

    t = Thread(target=idle)
    t.daemon = True
    t.start() 
开发者ID:edne,项目名称:pineal,代码行数:43,代码来源:listener.py

示例10: callback

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def callback(in_data, frame_count, time_info, status):
    signal = np.frombuffer(in_data, dtype=np.int16)
    pred = asr.transcribe(signal)
    if len(pred.strip()):
        print('"{}"'.format(pred))
    return (in_data, pa.paContinue) 
开发者ID:NVIDIA,项目名称:OpenSeq2Seq,代码行数:8,代码来源:demo_streaming_asr.py

示例11: pyaudio_callback

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def pyaudio_callback(in_data, frame_count, time_info, status):
    try:
        q.put(in_data)
    except Full:
        pass # discard
    return (None, pyaudio.paContinue)

# instantiate pyaudio 
开发者ID:watson-developer-cloud,项目名称:python-sdk,代码行数:10,代码来源:microphone-speech-to-text.py

示例12: _audio_sample_callback

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def _audio_sample_callback(self, in_data, frame_count, time_info, status):
        """Callback for when a new audio sample is acquired"""
        self._raw_audio_sample = np.fromstring(in_data, dtype=np.float32)

        self.pre_process_audio()
        self._invalidate_caches()
        self._invoke_callbacks()

        return (self._raw_audio_sample, pyaudio.paContinue) 
开发者ID:ahodges9,项目名称:LedFx,代码行数:11,代码来源:audio.py

示例13: _process_frame

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def _process_frame(self, data, frame_count, time_info, status_flag):
        data_array = np.fromstring(data, dtype=np.int16)
        freq0 = self._spectral_analyser.process_data(data_array)
        if freq0:
            # Onset detected
            print("Note detected; fundamental frequency: ", freq0)
            midi_note_value = int(hz_to_midi(freq0)[0])
            print("Midi note value: ", midi_note_value)
            note = RTNote(midi_note_value, 100, 0.5)
            self._synth.play_note(note)
        return (data, paContinue) 
开发者ID:aniawsz,项目名称:rtmonoaudio2midi,代码行数:13,代码来源:audiostream.py

示例14: callback

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def callback(self, in_data, frame_count, time_info, status):
        data = self.wf.readframes(frame_count)
        self.pos += frame_count
        return (data, pyaudio.paContinue) 
开发者ID:taylorlu,项目名称:Speaker-Diarization,代码行数:6,代码来源:player.py

示例15: callback

# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def callback(in_data, frame_count, time_info, status):
    global frame, indata, outdata
    indata.append(in_data)
    frame += 1
    return (outdata[frame * nchannel * chunk: (frame + 1) * nchannel * chunk], pyaudio.paContinue) 
开发者ID:hiromu,项目名称:robust_audio_ae,代码行数:7,代码来源:record.py


注:本文中的pyaudio.paContinue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。