本文整理汇总了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)
示例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
示例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
示例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
示例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)
示例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)
示例7: callback
# 需要导入模块: import pyaudio [as 别名]
# 或者: from pyaudio import paContinue [as 别名]
def callback(in_data, frame_count, time_info, status):
return (in_data, pyaudio.paContinue)
示例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)
示例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()
示例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)
示例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
示例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)
示例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)
示例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)
示例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)