Picovoice:修订间差异
无编辑摘要 |
无编辑摘要 |
||
第15行: | 第15行: | ||
=== 快速开始 === | === 快速开始 === | ||
以[[Python]] | 以[[Python]]语言示例,使用[[PyAudio]]录音,需要先安装好。: | ||
* 注册或登录https://console.picovoice.ai/ 获取AccessKey。 | * 注册或登录https://console.picovoice.ai/ 获取AccessKey。 | ||
* 安装pvporcupine: <code>pip3 install pvporcupine</code>。 | * 安装pvporcupine: <code>pip3 install pvporcupine</code>。 | ||
* 如果需要自定义唤醒词,需要在线训练,并下载指定文件位置,https://console.picovoice.ai/ppn。 | |||
* 使用非英语语言模型,需要下载指定位置,https://github.com/Picovoice/porcupine/tree/master/lib/common。 | |||
<syntaxhighlight lang="python" > | |||
import struct | |||
import pyaudio | |||
import pvporcupine | |||
porcupine = pvporcupine.create( | |||
access_key='你的AccessKey', | |||
keyword_paths=['/存储/路径/自定义唤醒词_zh_raspberry-pi_v3_0_0.ppn'], | |||
model_path='/存储/路径/语言模型/porcupine_params_zh.pv', | |||
) | |||
# Initialize PyAudio | |||
audio = pyaudio.PyAudio() | |||
stream = audio.open( | |||
rate=porcupine.sample_rate, | |||
channels=1, | |||
format=pyaudio.paInt16, | |||
input=True, | |||
frames_per_buffer=porcupine.frame_length, | |||
) | |||
# Main loop | |||
print("Listening for keywords...") | |||
try: | |||
while True: | |||
# Read audio data from the microphone | |||
audio_data = stream.read(porcupine.frame_length) | |||
audio_frame = struct.unpack_from("h" * porcupine.frame_length, audio_data) | |||
# Process audio frame with Porcupine | |||
keyword_index = porcupine.process(audio_frame) | |||
if keyword_index == 0: | |||
print("Keyword 0 detected!") | |||
elif keyword_index == 1: | |||
print("Keyword 1 detected!") | |||
finally: | |||
# Clean up resources | |||
stream.stop_stream() | |||
stream.close() | |||
audio.terminate() | |||
porcupine.delete() | |||
</syntaxhighlight> | |||
{{了解更多 | {{了解更多 |
2024年2月19日 (一) 02:09的最新版本
Picovoice是一家语音AI技术公司。提供一些产品,如Porcupine(离线唤醒词)。
简介
时间轴
Porcupine
Porcupine,产品全称Porcupine Wake Word,是一款离线轻量级的唤醒词引擎,支持多语言,多平台。免费账号每个月只支持3个用户和3个唤醒词训练。
快速开始
以Python语言示例,使用PyAudio录音,需要先安装好。:
- 注册或登录https://console.picovoice.ai/ 获取AccessKey。
- 安装pvporcupine:
pip3 install pvporcupine
。 - 如果需要自定义唤醒词,需要在线训练,并下载指定文件位置,https://console.picovoice.ai/ppn。
- 使用非英语语言模型,需要下载指定位置,https://github.com/Picovoice/porcupine/tree/master/lib/common。
import struct
import pyaudio
import pvporcupine
porcupine = pvporcupine.create(
access_key='你的AccessKey',
keyword_paths=['/存储/路径/自定义唤醒词_zh_raspberry-pi_v3_0_0.ppn'],
model_path='/存储/路径/语言模型/porcupine_params_zh.pv',
)
# Initialize PyAudio
audio = pyaudio.PyAudio()
stream = audio.open(
rate=porcupine.sample_rate,
channels=1,
format=pyaudio.paInt16,
input=True,
frames_per_buffer=porcupine.frame_length,
)
# Main loop
print("Listening for keywords...")
try:
while True:
# Read audio data from the microphone
audio_data = stream.read(porcupine.frame_length)
audio_frame = struct.unpack_from("h" * porcupine.frame_length, audio_data)
# Process audio frame with Porcupine
keyword_index = porcupine.process(audio_frame)
if keyword_index == 0:
print("Keyword 0 detected!")
elif keyword_index == 1:
print("Keyword 1 detected!")
finally:
# Clean up resources
stream.stop_stream()
stream.close()
audio.terminate()
porcupine.delete()
资源
官网
- Picovoice 官网:https://picovoice.ai
- Picovoice 文档:https://picovoice.ai/docs