Picovoice
由 Picovoice 在加拿大温哥华制造
Picovoice 是一个端到端平台,可让您根据自己的需求构建语音产品。与 Alexa 和 Google 服务不同,Picovoice 完全在设备上运行,并且更加准确。使用 Picovoice,可以从用户自然说话的表达中推断用户的意图,例如
"Hey Edison,将客厅的灯光设置为蓝色"
Picovoice 识别自定义唤醒词(Hey Edison
),然后从后续的语音命令中提取意图
{
"intent": "changeColor",
"slots": {
"location": "living room",
"color": "blue"
}
}
为什么选择 Picovoice
- 私有 & 安全: 所有内容都在本地处理。本质上私密;符合 HIPAA 和 GDPR。
- 精准: 对噪音和混响有弹性。远超基于云的替代方案。
- 跨平台: 一次设计,处处部署。使用熟悉的语言和框架进行构建。
- Arm Cortex-M、STM32、Arduino 和 i.MX RT
- Raspberry Pi、NVIDIA Jetson Nano 和 BeagleBone
- Android 和 iOS
- Chrome、Safari、Firefox 和 Edge
- Linux (x86_64)、macOS (x86_64, arm64) 和 Windows (x86_64)
- 自助式: 使用 Picovoice 控制台,在浏览器中即时设计和测试语音界面。
- 可靠: 无需持续连接即可本地运行。
- 零延迟: 以边缘为优先的架构消除了不可预测的网络延迟。
使用 Picovoice 构建
-
评估:Picovoice SDK 是一个跨平台库,可以用于将语音添加到任何产品中。它包括一些预训练的语音模型。SDK 采用 Apache 2.0 许可证,并在 GitHub 上提供,以鼓励独立的基准测试和集成测试。你将能够做出数据驱动的决策。
-
设计:Picovoice 控制台 是一个基于云的平台,可在网页浏览器中设计语音界面和训练语音模型。无需机器学习技能。只需用文本描述您所需的内容,然后导出经过训练的模型。
-
开发:导出的模型可以在不需要持续连接的情况下在 Picovoice SDK 上运行。SDK 支持各种平台和大量框架。Picovoice 控制台和 Picovoice SDK 使您能够快速设计、构建和迭代。
-
部署:无需维护复杂的云基础设施即可大规模部署。避免由主流技术公司施加的无限制云费用、限制和控制。
平台特性
自定义唤醒词
Picovoice 使用 Porcupine 唤醒词引擎 来检测给定的唤醒短语的说话。您可以使用 Picovoice 控制台训练自定义唤醒词,然后运行导出的唤醒词模型在 Picovoice SDK 上。
意图推理
Picovoice 利用 Rhino 语音到意图引擎,直接从特定兴趣域(一个“上下文”)内的口语命令中推断用户的意图。您可以使用 Picovoice 控制台设计和训练自定义上下文。然后,可以导出 Rhino 模型并在任何支持的平台 上使用 Picovoice SDK 运行。
目录
语言支持
- 英语、德语、法语、西班牙语、意大利语、日语、韩语和葡萄牙语。
- 对于商业客户,根据具体情况提供对其他语言的支持。
性能
Picovoice 利用 Porcupine 醒词引擎来检测特定唤醒词的发音。Porcupine 的开源基准测试可在此找到:此处。总结来说,与性能最佳的其他方案相比,Porcupine 的标准模型准确性提高了 5.4 倍。
Picovoice 依赖于 Rhino 语音到意图引擎,从特定兴趣域(一个“上下文”)内的口语命令中直接推断用户的意图。Rhino 的开源基准测试可在此找到:此处。Rhino 在性能上优于所有主流的基于云的替代方案。
Picovoice 控制台
Picovoice 控制台 是一个基于网页的平台,用于设计、测试和培训语音用户界面。使用 Picovoice 控制台,您可以训练自定义唤醒词和特定领域的自然语言理解(语音到意图)模型。
演示
如果使用 SSH,请使用以下命令克隆存储库:
git clone --recurse-submodules [email protected]:Picovoice/picovoice.git
如果使用 HTTPS,请使用以下命令克隆存储库:
git clone --recurse-submodules https://github.com/Picovoice/picovoice.git
Python 演示
sudo pip3 install picovoicedemo
从存储库的根目录运行以下命令:
picovoice_demo_mic \
--access_key ${ACCESS_KEY} \
--keyword_path resources/porcupine/resources/keyword_files/${PLATFORM}/porcupine_${PLATFORM}.ppn \
--context_path resources/rhino/resources/contexts/${PLATFORM}/smart_lighting_${PLATFORM}.rhn
将 ${PLATFORM}
替换为您在演示上运行的平台(例如 raspberry-pi
、beaglebone
、linux
、mac
或 windows
)。麦克风演示从麦克风打开音频流,检测给定的唤醒短语,并从随后的语音命令中推断意图。演示初始化后,会在控制台打印 [侦听 ...]
。然后说:
豪猪,将厨房的灯光调至紫色。
成功后,演示会在终端打印以下内容:
[wake word]
{
intent : 'changeColor'
slots : {
location : 'kitchen'
color : 'purple'
}
}
有关 Python 演示的更多信息,请参阅其 文档。
NodeJS 演示
安装演示包
npm install -g @picovoice/picovoice-node-demo
从存储库的根目录下执行
pv-mic-demo \
--access_key ${ACCESS_KEY} \
-k resources/porcupine/resources/keyword_files/${PLATFORM}/porcupine_${PLATFORM}.ppn \
-c resources/rhino/resources/contexts/${PLATFORM}/smart_lighting_${PLATFORM}.rhn
将${PLATFORM}
替换为您正在运行的演示平台(例如raspberry-pi
、linux
或mac
)。麦克风示例打开麦克风音频流,检测特定的唤醒词,并从后续的口语命令中推断意图。一旦演示初始化,它将打印正在监听唤醒词'porcupine'...
到控制台。然后说
Porcupine,打开灯光。
成功后,演示会在终端打印以下内容:
Inference:
{
"isUnderstood": true,
"intent": "changeLightState",
"slots": {
"state": "on"
}
}
有关详细信息,请参阅演示说明。
.NET 演示
从存储库的根目录运行以下命令:
dotnet run -p demo/dotnet/PicovoiceDemo/PicovoiceDemo.csproj -c MicDemo.Release -- \
--access_key ${ACCESS_KEY} \
--keyword_path resources/porcupine/resources/keyword_files/${PLATFORM}/porcupine_${PLATFORM}.ppn \
--context_path resources/rhino/resources/contexts/${PLATFORM}/smart_lighting_${PLATFORM}.rhn
将${PLATFORM}
替换为您正在运行的演示平台(例如linux
、mac
或windows
)。麦克风示例打开麦克风音频流,检测特定的唤醒词,并从后续的口语命令中推断意图。一旦演示初始化,它将打印正在监听...
到控制台。然后说
Porcupine,将厨房的灯光设置为橙色。
成功后,以下内容将打印到终端
[wake word]
{
intent : 'changeColor'
slots : {
location : 'kitchen'
color : 'orange'
}
}
有关.NET演示的更多信息,请访问demo/dotnet。
Java 演示
确保您的设备连接了一个工作的麦克风。然后从终端调用以下命令
cd demo/java
./gradlew build
cd build/libs
java -jar picovoice-mic-demo.jar \
-a ${ACCESS_KEY} \
-k resources/porcupine/resources/keyword_files/${PLATFORM}/porcupine_${PLATFORM}.ppn \
-c resources/rhino/resources/contexts/${PLATFORM}/smart_lighting_${PLATFORM}.rhn
将${PLATFORM}
替换为您正在运行的演示平台(例如linux
、mac
或windows
)。麦克风示例打开麦克风音频流,检测特定的唤醒词,并从后续的口语命令中推断意图。一旦演示初始化,它将打印正在监听...
到控制台。然后说
Porcupine,将厨房的灯光设置为橙色。
成功后,以下内容将打印到终端
[wake word]
{
intent : 'changeColor'
slots : {
location : 'kitchen'
color : 'orange'
}
}
有关Java演示的更多信息,请访问demo/java。
Go 演示
这些演示需要cgo
,这意味着需要一个如Mingw的gcc编译器。
从demo/go运行以下命令以构建和运行麦克风示例
go run micdemo/picovoice_mic_demo.go \
-access_key ${ACCESS_KEY} \
-keyword_path "../../resources/porcupine/resources/keyword_files/${PLATFORM}/porcupine_${PLATFORM}.ppn" \
-context_path "../../resources/rhino/resources/contexts/${PLATFORM}/smart_lighting_${PLATFORM}.rhn"
将${PLATFORM}
替换为您正在运行的演示平台(例如linux
、mac
或windows
)。麦克风示例打开麦克风音频流,检测特定的唤醒词,并从后续的口语命令中推断意图。一旦演示初始化,它将打印正在监听...
到控制台。然后说
Porcupine,将厨房的灯光设置为橙色。
成功后,以下内容将打印到终端
[wake word]
{
intent : 'changeColor'
slots : {
location : 'kitchen'
color : 'orange'
}
}
有关Go演示的更多信息,请访问 demo/go。
Unity 演示
要运行Picovoice Unity演示,请将最新的Picovoice Unity软件包导入到您的项目中,打开PicovoiceDemo场景并开始播放。要在其他平台或播放器中运行,请转到“文件 > 构建设置”,选择您的平台,然后点击“构建和运行”按钮。
要浏览演示源代码,请转到demo/unity。
Flutter 演示
要在Android或iOS上使用Flutter运行Picovoice演示,您必须在系统中安装Flutter SDK。安装后,您可以使用flutter doctor
运行命令来检查您的相关平台是否还缺少其他要求。环境设置完成后,启动模拟器或连接Android/iOS设备。
使用您选择的语言代码(例如:de
-> 德语,ko
-> 韩语)运行demo/flutter中的prepare_demo
脚本以设置您选择的演示语言。要查看可用语言列表,请不带语言代码运行prepare_demo
。
dart scripts/prepare_demo.dart ${LANGUAGE}
请将lib/main.dart文件中的AccessKey
替换。
final String accessKey = "{YOUR_ACCESS_KEY_HERE}"; // AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
从demo/flutter中运行以下命令以构建并将演示部署到您的设备
flutter run
演示应用程序启动后,按开始按钮并说出命令以开始推断上下文。要了解有关当前上下文信息的更多详细情况,请按应用程序右上角的上下文信息
按钮。
React Native 演示
要运行React Native Picovoice演示应用程序,您首先需要安装yarn并设置您的React Native环境。有关此信息,请参阅React Native的文档。环境设置完成后,您可以运行以下命令
Android上运行
cd demo/react-native
yarn android-install # sets up environment
yarn android-run # builds and deploys to Android
在iOS上运行
cd demo/react-native
yarn ios-install # sets up environment
yarn ios-run # builds and deploys to iOS
应用程序部署后,按下启动按钮,并说出
刺猬,关闭厨房的灯。
有关支持的全部命令,请参阅示例的readme。
Android示例
使用Android Studio,将demo/android/Activity作为一个Android项目打开,然后运行应用程序。按下启动按钮并说出
刺猬,关闭厨房的灯。
有关支持的全部命令,请参阅示例的readme。
iOS示例
BackgroundService示例在应用程序不处于焦点时在后台运行音频录制,并且保持在后台运行。ForegroundApp示例仅在应用程序处于焦点时运行。
背景服务Demo
为了运行这个演示,转到 demo/ios/BackgroundService 并运行
pod install
然后,使用 Xcode,打开生成的 PicovoiceBackgroundServiceDemo.xcworkspace
,并将您的 AccessKey
粘贴到 ContentView.swift
中的 ACCESS_KEY
变量中。构建并运行演示。
前台应用Demo
为了运行演示,转到 demo/ios/ForegroundApp 并运行
pod install
然后,使用 Xcode,打开生成的 PicovoiceForegroundAppDemo.xcworkspace
,并将您的 AccessKey
粘贴到 ContentView.swift
中的 ACCESS_KEY
变量中。构建并运行演示。
唤醒词检测与上下文推断
运行演示后,按下开始按钮并尝试说出以下内容
Picovoice,关闭客厅的灯光。
有关iOS演示的更多详细信息以及支持的完整命令列表,请参阅 演示的readme。
网页演示
原生JavaScript和HTML
从demo/web目录中使用yarn
或npm
安装依赖项,并使用带有语言代码的start
脚本来启动本地Web服务器。该服务器将以你选择的语言(例如pl
表示波兰语,ko
表示韩语)托管示例。要查看可用语言的列表,请在不带语言代码的情况下运行start
。
yarn
yarn start ${LANGUAGE}
(或)
npm install
npm run start ${LANGUAGE}
在浏览器中打开https://:5000
以尝试示例。
Angular示例
从demo/angular目录中使用yarn
或npm
安装依赖项,并使用带有语言代码的start
脚本来启动本地Web服务器。该服务器将以你选择的语言(例如pl
表示波兰语,ko
表示韩语)托管示例。要查看可用语言的列表,请在不带语言代码的情况下运行start
。
yarn
yarn start ${LANGUAGE}
(或)
npm install
npm run start ${LANGUAGE}
在浏览器中打开https://:4200
以尝试示例。
React示例
从demo/react目录中使用yarn
或npm
安装依赖项,并使用带有语言代码的start
脚本来启动本地Web服务器。该服务器将以你选择的语言(例如pl
表示波兰语,ko
表示韩语)托管示例。要查看可用语言的列表,请在不带语言代码的情况下运行start
。
yarn
yarn start ${LANGUAGE}
(或)
npm install
npm run start ${LANGUAGE}
在浏览器中打开https://:3000
以尝试示例。
Vue 演示
从 demo/vue 使用 yarn
或 npm
安装依赖项,然后使用带有语言代码的 start
脚本以启动一个本地 Web 服务器,该服务器以您选择的语言托管演示(例如 pl
–> 波兰语,ko
–> 韩语)。要查看可用语言的列表,请在没有语言代码的情况下运行 start
。
yarn
yarn start ${LANGUAGE}
(或)
npm install
npm run start ${LANGUAGE}
命令行输出将为您提供一个本机链接和端口号,您可以在浏览器中打开。
Rust 演示
从 demo/rust/micdemo 在终端运行以下命令以构建和运行 mic 演示
cargo run --release -- \
--keyword_path "../../../resources/porcupine/resources/keyword_files/${PLATFORM}/porcupine_${PLATFORM}.ppn" \
--context_path "../../../resources/rhino/resources/contexts/${PLATFORM}/smart_lighting_${PLATFORM}.rhn"
将${PLATFORM}
替换为您正在运行的演示平台(例如linux
、mac
或windows
)。麦克风示例打开麦克风音频流,检测特定的唤醒词,并从后续的口语命令中推断意图。一旦演示初始化,它将打印正在监听...
到控制台。然后说
Porcupine,将厨房的灯光设置为橙色。
成功后,以下内容将打印到终端
[wake word]
{
intent : 'changeColor'
slots : {
location : 'kitchen'
color : 'orange'
}
}
有关 Rust 演示的更多信息,请访问 demo/rust。
C 演示
C 演示需要 CMake 版本 3.4 或更高版本。
微型麦克风演示需要 miniaudio 以访问麦克风音频数据。
Windows 需要 MinGW 来构建演示。
麦克风演示
在仓库根部,使用以下命令构建
cmake -S demo/c/. -B demo/c/build && cmake --build demo/c/build --target picovoice_demo_mic
Linux (x86_64), macOS (x86_64), Raspberry Pi, 和 BeagleBone
使用以下命令列出输入音频设备
./demo/c/build/picovoice_demo_mic --show_audio_devices
使用以下命令运行演示
./demo/c/build/picovoice_demo_mic \
-a ${ACCESS_KEY}
-l ${PICOVOICE_LIBRARY_PATH} \
-p resources/porcupine/lib/common/porcupine_params.pv \
-k resources/porcupine/resources/keyword_files/${PLATFORM}/picovoice_${PLATFORM}.ppn \
-r resources/rhino/lib/common/rhino_params.pv \
-c resources/rhino/resources/contexts/${PLATFORM}/smart_lighting_${PLATFORM}.rhn \
-i {AUDIO_DEVICE_INDEX}
将 ${LIBRARY_PATH}
替换为 /sdk/c/lib 下的合适库路径,将 ${PLATFORM}
替换为您正在运行的平台的名称(linux
、raspberry-pi
、mac
或 beaglebone
),并将 ${AUDIO_DEVICE_INDEX}
替换为您的音频设备的索引。
Windows
使用以下命令列出输入音频设备
.\\demo\\c\\build\\picovoice_demo_mic.exe --show_audio_devices
使用以下命令运行演示
.\\demo\\c\\build\\picovoice_demo_mic.exe -a ${ACCESS_KEY} -l sdk/c/lib/windows/amd64/libpicovoice.dll -p resources/porcupine/lib/common/porcupine_params.pv -k resources/porcupine/resources/keyword_files/windows/picovoice_windows.ppn -r resources/rhino/lib/common/rhino_params.pv -c resources/rhino/resources/contexts/windows/smart_lighting_windows.rhn -i {AUDIO_DEVICE_INDEX}
将 ${AUDIO_DEVICE_INDEX}
替换为您的音频设备的索引。
该演示将打开音频流并等待检测到唤醒词 "Picovoice"。一旦检测到,它将根据智能照明系统的上下文从语音命令中推断出您的意图。例如,您可以说
"打开卧室的灯光"。
文件演示
在仓库根部,使用以下命令构建
cmake -S demo/c/. -B demo/c/build && cmake --build demo/c/build --target picovoice_demo_file
Linux (x86_64), macOS (x86_64), Raspberry Pi, 和 BeagleBone
使用以下命令运行演示
./demo/c/build/picovoice_demo_file \
-a ${ACCESS_KEY}
-l ${LIBRARY_PATH} \
-p resources/porcupine/lib/common/porcupine_params.pv \
-k resources/porcupine/resources/keyword_files/${PLATFORM}/picovoice_${PLATFORM}.ppn \
-r resources/rhino/lib/common/rhino_params.pv \
-c resources/rhino/resources/contexts/${PLATFORM}/coffee_maker_${PLATFORM}.rhn \
-w resources/audio_samples/picovoice-coffee.wav
将 ${LIBRARY_PATH}
替换为 sdk/c/lib 下适当的库的路径,将 ${PLATFORM}
替换为你正在运行的平台名称(linux
、raspberry-pi
、mac
或 beaglebone
)。
Windows
使用以下命令运行演示
.\\demo\\c\\build\\picovoice_demo_file.exe -a ${ACCESS_KEY} -l sdk/c/lib/windows/amd64/libpicovoice.dll -p resources/porcupine/lib/common/porcupine_params.pv -k resources/porcupine/resources/keyword_files/windows/picovoice_windows.ppn -r resources/rhino/lib/common/rhino_params.pv -c resources/rhino/resources/contexts/windows/coffee_maker_windows.rhn -w resources/audio_samples/picovoice-coffee.wav
该示例打开 WAV 文件。它检测唤醒词,并在咖啡机系统上下文中推断意图。
有关 C 示例的更多信息,请访问 demo/c。
微控制器示例
在 mcu 示例 文件夹中,有几个针对不同开发板的项目。
SDK
Python
安装软件包
pip3 install picovoice
创建 Picovoice 的新实例
from picovoice import Picovoice
access_key = "${ACCESS_KEY}" # AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
keyword_path = ...
def wake_word_callback():
pass
context_path = ...
def inference_callback(inference):
print(inference.is_understood)
print(inference.intent)
print(inference.slots)
handle = Picovoice(
access_key=access_key,
keyword_path=keyword_path,
wake_word_callback=wake_word_callback,
context_path=context_path,
inference_callback=inference_callback)
handle
是 Picovoice 运行时引擎的一个实例。它检测位于 keyword_path
文件中定义的唤醒词的发音。检测到唤醒词后,它会从位于 context_path
文件中定义的上下文中推断用户的意图。 keyword_path
是指向 Porcupine 唤醒词引擎 关键字文件(扩展名为 .ppn
)的绝对路径。 context_path
是指向 Rhino 语音到意图引擎 上下文文件(扩展名为 .rhn
)的绝对路径。 wake_word_callback
在检测到唤醒词时被调用,而 inference_callback
在后续语音命令推断完成后被调用。
实例化时,可以通过 handle.sample_rate
获取所需的采样率。每帧预期的音频样本数是 handle.frame_length
。该引擎接受 16 位线性编码的 PCM 数据,并处理单声道音频。支持的命令集合可以通过 handle.context_info
以 YAML 格式检索。
def get_next_audio_frame():
pass
while True:
handle.process(get_next_audio_frame())
完成工作时,必须显式释放资源 handle.delete()
。
NodeJS
NodeJS 的 Picovoice SDK 可从 NPM 获取。
yarn add @picovoice/picovoice-node
(或)
npm install @picovoice/picovoice-node
SDK 提供了 Picovoice
类。使用 Porcupine 关键字(扩展名为 .ppn
)、Rhino 上下文文件(扩展名为 .rhn
)以及分别在唤醒词检测和命令推断完成事件上调用的回调函数来创建此类的实例。
const Picovoice = require("@picovoice/picovoice-node");
const accessKey = "${ACCESS_KEY}"; // Obtained from the Picovoice Console (https://console.picovoice.ai/)
let keywordCallback = function (keyword) {
console.log(`Wake word detected`);
};
let inferenceCallback = function (inference) {
console.log("Inference:");
console.log(JSON.stringify(inference, null, 4));
};
let handle = new Picovoice(
accessKey,
keywordArgument,
keywordCallback,
contextPath,
inferenceCallback
);
keywordArgument
可以是 Porcupine 关键字文件(.ppn)的路径,或者内置关键字(整型枚举)之一。 contextPath
是 Rhino 上下文文件(.rhn)的路径。
构建 Picovoice 类后,通过其 process
方法发送音频帧。Picovoice 会内部在唤醒词检测和推断之间切换。Picovoice 类包含用于音频格式的 frameLength
和 sampleRate
属性。
// process audio frames that match the Picovoice requirements (16-bit linear pcm audio, single-channel)
while (true) {
handle.process(frame);
}
随着音频通过 Picovoice 引擎进行处理,回调将被触发。
.NET
您可以通过在 Visual Studio 中添加最新的 Picovoice NuGet 包 或使用 .NET CLI 来安装最新的 Picovoice 版本。
dotnet add package Picovoice
要创建 Picovoice 实例,请执行以下操作:
using Pv;
const string accessKey = "${ACCESS_KEY}"; // obtained from Picovoice Console (https://console.picovoice.ai/)
string keywordPath = "/absolute/path/to/keyword.ppn";
void wakeWordCallback() => {..}
string contextPath = "/absolute/path/to/context.rhn";
void inferenceCallback(Inference inference)
{
// `inference` exposes three immutable properties:
// (1) `IsUnderstood`
// (2) `Intent`
// (3) `Slots`
// ..
}
Picovoice handle = Picovoice.Create(accessKey,
keywordPath,
wakeWordCallback,
contextPath,
inferenceCallback);
handle
是 Picovoice 运行时引擎的实例,用于检测在位于 keywordPath
文件中定义的唤醒词。检测到唤醒词后,它开始从位于 contextPath
文件中定义的上下文中后续语音命令推断用户的意图。 accessKey
是您的 Picovoice AccessKey
。 keywordPath
是指向 Porcupine 唤醒词引擎 关键字文件(.ppn
扩展名)的绝对路径。 contextPath
是指向 Rhino 语音到意图引擎 上下文文件(.rhn
扩展名)的绝对路径。 wakeWordCallback
在检测到唤醒词时被调用,而 inferenceCallback
在后续语音命令推断完成后被调用。
实例化时,可以通过 handle.SampleRate
获取所需的采样率。每帧预期的音频样本数为 handle.FrameLength
。Picovoice 引擎接受 16 位线性编码的 PCM 音频并且操作单通道音频。
short[] GetNextAudioFrame()
{
// .. get audioFrame
return audioFrame;
}
while(true)
{
handle.Process(GetNextAudioFrame());
}
Picovoice 的资源将由垃圾收集器释放,但为了在使用后立即释放资源,请在其中使用 using
语句。
using(Picovoice handle = Picovoice.Create(accessKey, keywordPath, wakeWordCallback, contextPath, inferenceCallback))
{
// .. Picovoice usage here
}
Java
Picovoice Java 库可以从 Maven Central 获得,地址是 ai.picovoice:picovoice-java:${version}
。
使用 Picovoice Builder 是创建引擎实例最容易的方法。
import ai.picovoice.picovoice.*;
String keywordPath = "/absolute/path/to/keyword.ppn";
final String accessKey = "${ACCESS_KEY}"; // AccessKey obtained from [Picovoice Console](https://console.picovoice.ai/)
PicovoiceWakeWordCallback wakeWordCallback = () -> {..};
String contextPath = "/absolute/path/to/context.rhn";
PicovoiceInferenceCallback inferenceCallback = inference -> {
// `inference` exposes three getters:
// (1) `getIsUnderstood()`
// (2) `getIntent()`
// (3) `getSlots()`
// ..
};
try {
Picovoice handle = new Picovoice.Builder()
.setAccessKey(accessKey)
.setKeywordPath(keywordPath)
.setWakeWordCallback(wakeWordCallback)
.setContextPath(contextPath)
.setInferenceCallback(inferenceCallback)
.build();
} catch (PicovoiceException e) { }
handle
是 Picovoice 运行时引擎的实例,用于检测在位于 keywordPath
文件中定义的唤醒词。检测到唤醒词后,它开始从位于 contextPath
文件中定义的上下文中后续语音命令推断用户的意图。 keywordPath
是指向 Porcupine 唤醒词引擎 关键字文件(.ppn
扩展名)的绝对路径。 contextPath
是指向 Rhino 语音到意图引擎 上下文文件(.rhn
扩展名)的绝对路径。 wakeWordCallback
在检测到唤醒词时被调用,而 inferenceCallback
在后续语音命令推断完成后被调用。
实例化时,可以通过 handle.getSampleRate()
获取所需的采样率。每帧预期的音频样本数为 handle.getFrameLength()
。Picovoice 引擎接受 16 位线性编码的 PCM 音频并且操作单通道音频。
short[] getNextAudioFrame()
{
// .. get audioFrame
return audioFrame;
}
while(true)
{
handle.process(getNextAudioFrame());
}
使用完 Picovoice 后,请确保明确释放其资源。
handle.delete();
Go
要安装 Picovoice Go 模块到您的项目中,请使用以下命令
go get github.com/Picovoice/picovoice/sdk/go
要使用默认参数创建引擎实例,请使用 NewPicovoice
函数。您必须提供一个 Porcupine 关键字文件、一个唤醒词检测回调函数、一个 Rhino 上下文文件和推理回调函数。然后,您必须调用 Init()
。
. "github.com/Picovoice/picovoice/sdk/go/v2"
rhn "github.com/Picovoice/rhino/binding/go/v2"
const accessKey string = "${ACCESS_KEY}" // obtained from Picovoice Console (https://console.picovoice.ai/)
keywordPath := "/path/to/keyword/file.ppn"
wakeWordCallback := func() {
// let user know wake word detected
}
contextPath := "/path/to/keyword/file.rhn"
inferenceCallback := func(inference rhn.RhinoInference) {
if inference.IsUnderstood {
intent := inference.Intent
slots := inference.Slots
// add code to take action based on inferred intent and slot values
} else {
// add code to handle unsupported commands
}
}
picovoice := NewPicovoice(
accessKey,
keywordPath,
wakeWordCallback,
contextPath,
inferenceCallback)
err := picovoice.Init()
if err != nil {
// handle error
}
当检测到由 keywordPath
定义的唤醒词时,它将从 contextPath
定义的上下文中捕捉到的后续语音命令开始推断用户的意图。accessKey
是您的 Picovoice AccessKey
。 keywordPath
是指向 Porcupine 唤醒词引擎 关键字文件的绝对路径(后缀为 .ppn
)。contextPath
是指向 Rhino 语音到意图引擎 上下文文件的绝对路径(后缀为 .rhn
)。wakeWordCallback
在检测到唤醒词时调用,而 inferenceCallback
在跟随语音命令推断完成后调用。
在实例化时,可以通过 SampleRate
获取有效样本率。每帧预期的音频样本数是 FrameLength
。引擎接受16位线性编码的PCM,并处理单声道音频。
func getNextFrameAudio() []int16 {
// get audio frame
}
for {
err := picovoice.Process(getNextFrameAudio())
}
操作完毕后,必须显式释放资源
picovoice.Delete()
Unity
将最新的 Picovoice Unity 包 导入您的 Unity 项目中。
SDK 提供了两个 API
高级 API
PicovoiceManager 提供了一个高级 API,它可以处理语音录制。这是起步最快的途径。
PicovoiceManager.Create
构造函数将使用您传递给它的 Porcupine 关键字和 Rhino 上下文文件创建一个 PicovoiceManager 实例。
using Pv.Unity;
PicovoiceManager _picovoiceManager = new PicovoiceManager(
"/path/to/keyword/file.ppn",
() => {},
"/path/to/context/file.rhn",
(inference) => {};
一旦实例化了一个 PicovoiceManager,您可以通过调用
try
{
_picovoiceManager.Start();
}
catch(Exception ex)
{
Debug.LogError(ex.ToString());
}
// .. use picovoice
_picovoiceManager.Stop();
PicovoiceManager 使用我们的 unity-voice-processor Unity 包来捕获音频帧并自动将其传递到 Picovoice 平台。
低级 API
Picovoice 为那些想将其整合到现有音频处理流程中的人提供了对 Picovoice 平台的低级别访问。
Picovoice
是通过将 Porcupine 关键词文件和 Rhino 上下文文件传递给 Create
静态构造函数创建的。
using Pv.Unity;
try
{
Picovoice _picovoice = Picovoice.Create(
"path/to/keyword/file.ppn",
OnWakeWordDetected,
"path/to/context/file.rhn",
OnInferenceResult);
}
catch (Exception ex)
{
// handle Picovoice init error
}
要使用 Picovoice,您必须将音频帧传递给 Process
函数。在检测到唤醒词以及后续命令时,回调将自动触发。
short[] GetNextAudioFrame()
{
// .. get audioFrame
return audioFrame;
}
short[] buffer = GetNextAudioFrame();
try
{
_picovoice.Process(buffer);
}
catch (Exception ex)
{
Debug.LogError(ex.ToString());
}
为了使 Process
正确工作,提供的音频必须是单声道 16 位线性编码的。
Picovoice 实现了 IDisposable
接口,因此您可以在 using
块中使用 Picovoice。如果您不使用 using
块,资源将由垃圾回收器自动释放,或者您可以明确释放资源,如下所示
_picovoice.Dispose();
Flutter
将 Picovoice Flutter 包 添加到您的 pub.yaml 文件中。
dependencies:
picovoice: ^<version>
SDK 提供了两个 API
高级 API
PicovoiceManager 提供了一个高级 API,该 API 处理音频记录。此类是快速入门的便捷方式。
PicovoiceManager.create
静态构造函数将创建一个 PicovoiceManager 实例,该实例使用您传递的 Porcupine 关键词文件和 Rhino 上下文文件。
import 'package:picovoice/picovoice_manager.dart';
import 'package:picovoice/picovoice_error.dart';
final String accessKey = "{ACCESS_KEY}"; // AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
void createPicovoiceManager() {
_picovoiceManager = PicovoiceManager.create(
accessKey,
"/path/to/keyword/file.ppn",
_wakeWordCallback,
"/path/to/context/file.rhn",
_inferenceCallback);
}
wakeWordCallback
和 inferenceCallback
参数是当检测到唤醒词以及进行推理时您希望执行的功能。
inferenceCallback
回调函数接受一个 RhinoInference
实例作为参数,其中包含以下变量
- isUnderstood - 如果基于上下文 Rhino 理解了所听到的内容则为 true,否则为 false
- intent - 如果
isUnderstood
为 false,则为 null,否则为推理出的意图名称 - slots - 如果
isUnderstood
为 false,则为 null,否则为推理出的槽位键值对的字典
一旦实例化了一个 PicovoiceManager,您可以通过调用
await _picovoiceManager.start();
// .. use for detecting wake words and commands
await _picovoiceManager.stop();
我们的 flutter_voice_processor Flutter 插件处理音频捕获并将帧传递给您进行 Picovoice。
低级 API
Picovoice 为希望将其集成到现有音频处理管道中的人提供了对 Picovoice 平台的低级访问。
通过将 Porcupine 关键词文件和 Rhino 上下文文件传递到 create
静态构造函数中创建 Picovoice
。灵敏度、模型文件和 requireEndpoint 是可选的。
import 'package:picovoice/picovoice_manager.dart';
import 'package:picovoice/picovoice_error.dart';
final String accessKey = "{ACCESS_KEY}"; // AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
void createPicovoice() async {
double porcupineSensitivity = 0.7;
double rhinoSensitivity = 0.6;
try {
_picovoice = await Picovoice.create(
accessKey,
"/path/to/keyword/file.ppn",
wakeWordCallback,
"/path/to/context/file.rhn",
inferenceCallback,
porcupineSensitivity,
rhinoSensitivity,
"/path/to/porcupine/model.pv",
"/path/to/rhino/model.pv",
requireEndpoint);
} on PicovoiceException catch (err) {
// handle picovoice init error
}
}
要使用 Picovoice,只需将音频帧传递给 process
函数。一旦检测到唤醒词,随后检测到后续命令时,将自动触发回调函数。
List<int> buffer = getAudioFrame();
try {
_picovoice.process(buffer);
} on PicovoiceException catch (error) {
// handle error
}
// once you are done using Picovoice
_picovoice.delete();
React Native
首先通过 yarn 或 npm 将我们的 React Native 模块添加到项目中。
yarn add @picovoice/react-native-voice-processor
yarn add @picovoice/porcupine-react-native
yarn add @picovoice/rhino-react-native
yarn add @picovoice/picovoice-react-native
@picovoice/picovoice-react-native 包提供了一组高级和低级 API,用于将 Picovoice 集成到应用程序中。
高级 API
PicovoiceManager 提供了一个高级 API,它负责音频录制。此类是快速入门的最快方式。
PicovoiceManager.create
静态构造函数将创建一个 PicovoiceManager 实例,该实例使用您传递的 Porcupine 关键词文件和 Rhino 上下文文件。
const accessKey = "${ACCESS_KEY}"; // obtained from Picovoice Console (https://console.picovoice.ai/)
this._picovoiceManager = PicovoiceManager.create(
accessKey,
'/path/to/keyword/file.ppn',
wakeWordCallback,
'/path/to/context/file.rhn',
inferenceCallback);
wakeWordCallback
和 inferenceCallback
参数是当检测到唤醒词以及进行推理时您希望执行的功能。
一旦实例化了一个 PicovoiceManager,您可以通过调用
try {
let didStart = await this._picovoiceManager.start();
} catch(err) { }
// .. use for detecting wake words and commands
let didStop = await this._picovoiceManager.stop();
@picovoice/react-native-voice-processor 模块处理音频捕获并将帧传递给 Picovoice。
低级 API
Picovoice 为希望将其集成到现有音频处理管道中的人提供了对 Picovoice 平台的低级访问。
Picovoice
通过传递 Porcupine 关键词文件和 Rhino 上下文文件到 create
静态构造函数中创建。灵敏度和模型文件是可选的。
const accessKey = "${ACCESS_KEY}"; // obtained from Picovoice Console (https://console.picovoice.ai/)
async createPicovoice() {
let porcupineSensitivity = 0.7;
let rhinoSensitivity = 0.6;
let requireEndpoint = false;
try {
this._picovoice = await Picovoice.create(
accessKey,
'/path/to/keyword/file.ppn',
wakeWordCallback,
'/path/to/context/file.rhn',
inferenceCallback,
processErrorCallback,
porcupineSensitivity,
rhinoSensitivity,
"/path/to/porcupine/model.pv",
"/path/to/rhino/model.pv",
requireEndpoint);
} catch (err) {
// handle error
}
}
要使用 Picovoice,只需将音频帧传递给 process
函数。一旦检测到唤醒词,随后检测到后续命令时,将自动触发回调函数。
let buffer = getAudioFrame();
try {
await this._picovoice.process(buffer);
} catch (e) {
// handle error
}
// once you are done
this._picovoice.delete();
Android
Porcupine 可以在 Maven Central 上找到。要将该包包含到您的 Android 项目中,确保您已在顶级 build.gradle
文件中包含了 mavenCentral()
,然后将其添加到您的应用的 build.gradle
dependencies {
// ...
implementation 'ai.picovoice:picovoice-android:${LATEST_VERSION}'
}
将 Picovoice 集成到 Android 应用程序中有两种可能性。
高级 API
PicovoiceManager 为将 Picovoice 集成到 Android 应用程序提供了一个高级 API。它负责管理创建输入音频流、将其输入到 Picovoice 引擎以及检测唤醒词和在推理完成时调用用户定义的回调相关的所有活动。
final String accessKey = "${ACCESS_KEY}"; // AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
final String keywordPath = "/path/to/keyword.ppn"; // path relative to 'assets' folder
final String contextPath = "/path/to/context.rhn"; // path relative to 'assets' folder
PicovoiceManager manager = new PicovoiceManager.Builder()
.setAccessKey(accessKey)
.setKeywordPath(keywordPath)
.setWakeWordCallback(new PicovoiceWakeWordCallback() {
@Override
public void invoke() {
// logic to execute upon detection of wake word
}
})
.setContextPath(contextPath)
.setInferenceCallback(new PicovoiceInferenceCallback() {
@Override
public void invoke(final RhinoInference inference) {
// logic to execute upon completion of intent inference
}
})
.build(appContext);
);
关键字(.ppn
)和上下文(.rhn
)文件应放置在 Android 项目的 assets 文件夹(src/main/assets/
)下。
appContext
参数是 Android 应用程序上下文 - 这用于从 APK 中提取 Picovoice 资源。
初始化后,可以使用以下方法处理输入音频
manager.start();
使用以下方法停止管理器
manager.stop();
低级 API
Picovoice.java 为 Android 提供了一个低级绑定。可以按照以下方式初始化
import ai.picovoice.picovoice.*;
try {
Picovoice picovoice = new Picovoice.Builder()
.setPorcupineModelPath("/path/to/porcupine/model.pv")
.setKeywordPath("/path/to/keyword.ppn")
.setPorcupineSensitivity(0.7f)
.setWakeWordCallback(new PicovoiceWakeWordCallback() {
@Override
public void invoke() {
// logic to execute upon detection of wake word
}
})
.setRhinoModelPath("/path/to/rhino/model.pv")
.setContextPath("/path/to/context.rhn")
.setRhinoSensitivity(0.55f)
.setInferenceCallback(new PicovoiceInferenceCallback() {
@Override
public void invoke(final RhinoInference inference) {
// logic to execute upon completion of intent inference
}
})
.build(appContext);
} catch(PicovoiceException ex) { }
关键字(.ppn
)、上下文(.rhn
)和模型(.pv
)文件应置于 Android 项目的 assets 文件夹(src/main/assets/
)中。
一旦初始化,可以使用 picovoice
处理传入的音频。
private short[] getNextAudioFrame();
while (true) {
try {
picovoice.process(getNextAudioFrame());
} catch (PicovoiceException e) {
// error handling logic
}
}
最后,务必显式释放所获取的资源,因为绑定类不依赖于垃圾回收器来释放本地资源
picovoice.delete();
iOS
Picovoice iOS SDK可通过Cocoapods获取。将其导入到您的iOS项目中,需要安装Cocoapods并在Podfile中添加以下行
pod 'Picovoice-iOS'
将Picovoice集成到iOS应用程序中有两种可能性。
高级API
PicovoiceManager类管理创建音频输入流、将其馈送到Picovoice引擎以及检测唤醒词和完成意图推断时的用户定义回调的所有相关活动。该类可以按以下方式初始化
import Picovoice
let accessKey = "${ACCESS_KEY}" // obtained from Picovoice Console (https://console.picovoice.ai/)
let manager = PicovoiceManager(
accessKey: accessKey,
keywordPath: "/path/to/keyword.ppn",
onWakeWordDetection: {
// logic to execute upon detection of wake word
},
contextPath: "/path/to/context.rhn",
onInference: { inference in
// logic to execute upon completion of intent inference
})
初始化后,可以使用manager.start()
处理输入音频。可以通过使用manager.stop()
来中断处理。
低级API
Picovoice.swift提供了一种API,可以将音频从您自己的音频管道传递到Picovoice平台以进行唤醒词检测和意图推断。
要构建一个实例,您需要提供一个Porcupine关键字文件(.ppn)、一个Rhino上下文文件(.rhn)以及在检测到唤醒词和进行推断时调用的回调。灵敏度和模型参数是可选的
import Picovoice
let accessKey = "${ACCESS_KEY}" // obtained from Picovoice Console (https://console.picovoice.ai/)
do {
let picovoice = try Picovoice(
accessKey: accessKey,
keywordPath: "/path/to/keyword.ppn",
porcupineSensitivity: 0.4,
porcupineModelPath: "/path/to/porcupine/model.pv"
onWakeWordDetection: {
// logic to execute upon detection of wake word
},
contextPath: "/path/to/context.rhn",
rhinoSensitivity: 0.7,
rhinoModelPath: "/path/to/rhino/model.pv"
onInference: { inference in
// logic to execute upon completion of intent inference
})
} catch { }
初始化后,可以使用picovoice
处理传入的音频。类的基本逻辑将处理唤醒词检测和意图推断之间的切换,以及调用相关事件。
func getNextAudioFrame() -> [Int16] {
// .. get audioFrame
return audioFrame;
}
while (true) {
do {
try picovoice.process(getNextAudioFrame());
} catch { }
}
完成Picovoice实例后,您可以强制释放其本地资源,而不是等待垃圾收集器
picovoice.delete();
Web
使用yarn安装Web SDK
yarn add @picovoice/picovoice-web
或者使用npm
npm install --save @picovoice/picovoice-web
使用PicovoiceWorker
创建引擎实例并在音频输入流上运行
import { PicovoiceWorker } from "@picovoice/picovoice-web";
function wakeWordCallback(detection: PorcupineDetection) {
console.log(`Porcupine detected keyword: ${detection.label}`);
}
function inferenceCallback(inference: RhinoInference) {
if (inference.isFinalized) {
if (inference.isUnderstood) {
console.log(inference.intent)
console.log(inference.slots)
}
}
}
function getAudioData(): Int16Array {
... // function to get audio data
return new Int16Array();
}
const picovoice = await PicovoiceWorker.create(
"${ACCESS_KEY}",
keyword,
wakeWordCallback,
porcupineModel,
context,
inferenceCallback,
rhinoModel
);
for (; ;) {
picovoice.process(getAudioData());
// break on some condition
}
将${ACCESS_KEY}
替换为您从Picovoice控制台获取的密钥。
操作完成后,使用picovoice.release()
释放Picovoice分配的资源。
Angular
yarn add @picovoice/picovoice-angular @picovoice/web-voice-processor
(或)
npm install @picovoice/picovoice-angular @picovoice/web-voice-processor
import { Subscription } from "rxjs"
import { PicovoiceService } from "@picovoice/picovoice-angular"
...
constructor(private picovoiceService: PicovoiceService) {
this.wakeWordDetectionSubscription = picovoiceService.wakeWordDetection$.subscribe(
(wakeWordDetection: PorcupineDetection) => {
this.inference = null;
this.wakeWordDetection = wakeWordDetection;
}
);
this.inferenceSubscription = picovoiceService.inference$.subscribe(
(inference: RhinoInference) => {
this.wakeWordDetection = null;
this.inference = inference;
}
);
this.contextInfoSubscription = picovoiceService.contextInfo$.subscribe(
(contextInfo: string | null) => {
this.contextInfo = contextInfo;
}
);
this.isLoadedSubscription = picovoiceService.isLoaded$.subscribe(
(isLoaded: boolean) => {
this.isLoaded = isLoaded;
}
);
this.isListeningSubscription = picovoiceService.isListening$.subscribe(
(isListening: boolean) => {
this.isListening = isListening;
}
);
this.errorSubscription = picovoiceService.error$.subscribe(
(error: string | null) => {
this.error = error;
}
);
}
async ngOnInit() {
try {
await this.picovoiceService.init(
accessKey,
porcupineKeyword,
porcupineModel,
rhinoContext,
rhinoModel
);
}
catch (error) {
console.error(error)
}
}
ngOnDestroy() {
this.wakeWordDetectionSubscription.unsubscribe();
this.inferenceSubscription.unsubscribe();
this.contextInfoSubscription.unsubscribe();
this.isLoadedSubscription.unsubscribe();
this.isListeningSubscription.unsubscribe();
this.errorSubscription.unsubscribe();
this.picovoiceService.release();
}
React
yarn add @picovoice/picovoice-react @picovoice/web-voice-processor
(或)
npm install @picovoice/picovoice-react @picovoice/web-voice-processor
import { usePicovoice } from '@picovoice/picovoice-react';
function App(props) {
const {
wakeWordDetection,
inference,
contextInfo,
isLoaded,
isListening,
error,
init,
start,
stop,
release,
} = usePicovoice();
const initEngine = async () => {
await init(
${ACCESS_KEY},
porcupineKeyword,
porcupineModel,
rhinoContext,
rhinoModel
);
await start();
}
useEffect(() => {
if (wakeWordDetection !== null) {
console.log(`Picovoice detected keyword: ${wakeWordDetection.label}`);
}
}, [wakeWordDetection])
useEffect(() => {
if (inference !== null) {
if (inference.isUnderstood) {
console.log(inference.intent)
console.log(inference.slots)
}
}
}, [inference])
}
Vue
yarn add @picovoice/picovoice-vue @picovoice/web-voice-processor
(或)
npm install @picovoice/picovoice-vue @picovoice/web-voice-processor
<script lang='ts'>
import { usePicovoice } from '@picovoice/picovoice-vue';
export default {
data() {
const {
state,
init,
start,
stop,
release
} = usePicovoice();
init(
${ACCESS_KEY},
{
label: "Picovoice",
publicPath: "picovoice_wasm.ppn",
},
{ publicPath: "porcupine_params.pv" },
{ publicPath: "clock_wasm.rhn" },
{ publicPath: "rhino_params.pv" },
);
return {
state,
start,
stop,
release
}
},
watch: {
"state.wakeWordDetection": function(wakeWord) {
if (wakeWord !== null) {
console.log(wakeWord)
}
},
"state.inference": function(inference) {
if (inference !== null) {
console.log(inference)
}
},
"state.contextInfo": function(contextInfo) {
if (contextInfo !== null) {
console.log(contextInfo)
}
},
"state.isLoaded": function(isLoaded) {
console.log(isLoaded)
},
"state.isListening": function(isListening) {
console.log(isListening)
},
"state.error": function(error) {
console.error(error)
},
},
onBeforeDestroy() {
this.release();
},
};
</script>
Rust
要将picovoice库添加到您的应用程序中,将picovoice
添加到应用程序的Cargo.toml
清单中
[dependencies]
picovoice = "*"
要使用默认参数创建引擎实例,请使用 PicovoiceBuilder
函数。您必须提供 Porcupine 关键词文件、唤醒词检测回调函数、Rhino 上下文文件以及推理回调函数。然后,必须调用 init()
use picovoice::{rhino::RhinoInference, PicovoiceBuilder};
let wake_word_callback = || {
// let user know wake word detected
};
let inference_callback = |inference: RhinoInference| {
if inference.is_understood {
let intent = inference.intent.unwrap();
let slots = inference.slots;
// add code to take action based on inferred intent and slot values
} else {
// add code to handle unsupported commands
}
};
let mut picovoice = PicovoiceBuilder::new(
keyword_path,
wake_word_callback,
context_path,
inference_callback,
).init().expect("Failed to create picovoice");
在检测到由 keyword_path
定义的唤醒词后,它将根据存储在 context_path
定位的文件中定义的上下文,对后续语音命令中用户意图进行推理。 keyword_path
是指向Porcupine 唤醒词引擎关键词文件(具有 .ppn
后缀)的绝对路径。 context_path
是指向Rhino 语音到意图引擎上下文文件(具有 .rhn
后缀)的绝对路径。在检测到唤醒短语时调用 wake_word_callback
,在后续语音命令推理完成后调用 inference_callback
。
在实例化后,可以通过 sample_rate()
获取有效采样率。每帧预期的音频样本数是 frame_length()
。该引擎接受 16 位线性编码的 PCM 并在单通道音频上操作
fn next_audio_frame() -> Vec<i16> {
// get audio frame
}
loop {
picovoice.process(&next_audio_frame()).expect("Picovoice failed to process audio");
}
C
Picovoice 使用 ANSI C 实现,因此可以将其直接链接到 C 应用程序。其公共头文件(sdk/c/include/pv_picovoice.h)包含相关信息。Picovoice 对象的实例可以按照以下方式构建。
const char* ACCESS_KEY = "${ACCESS_KEY}"; // AccessKey string obtained from [Picovoice Console](https://console.picovoice.ai/)
const char *porcupine_model_path = ... // Available at resources/porcupine/lib/common/porcupine_params.pv
const char *keyword_path = ...
const float porcupine_sensitivity = 0.5f;
const char *rhino_model_path = ... // Available at resources/rhino/lib/common/rhino_params.pv
const char *context_path = ...
const float rhino_sensitivity = 0.5f;
const bool require_endpoint = true;
static void wake_word_callback(void) {
// take action upon detection of wake word
}
static void inference_callback(pv_inference_t *inference) {
// `inference` exposes three immutable properties:
// (1) `IsUnderstood`
// (2) `Intent`
// (3) `Slots`
// take action based on inferred intent
pv_inference_delete(inference);
}
pv_picovoice_t *handle = NULL;
pv_status_t status = pv_picovoice_init(
access_key,
porcupine_model_path,
keyword_path,
porcupine_sensitivity,
wake_word_callback,
rhino_model_path,
context_path,
rhino_sensitivity,
require_endpoint,
inference_callback,
&handle);
if (status != PV_STATUS_SUCCESS) {
// error handling logic
}
敏感性是允许开发人员以误报率为代价,权衡漏报率的参数。它是一个 [0, 1] 范围内的浮点数。更高的敏感性可以降低误报率(假拒绝率),但会增加误报率。
handle
是 Picovoice 运行时引擎的实例,该引擎检测由 keyword_path
提供的唤醒词的发音。在检测到唤醒词后,它开始根据在 context_path
中定义的上下文对后续语音命令进行推理。在检测到唤醒词时调用 wake_word_callback
,在完成后续语音命令推理后调用 inference_callback
。
Picovoice 接受单个通道、16 位 PCM 音频。可以使用 pv_sample_rate()
获取采样率。最后,Picovoice 以连续的块(称为帧)的形式接受输入音频,可以使用 pv_porcupine_frame_length()
获取帧的长度。
extern const int16_t *get_next_audio_frame(void);
while (true) {
const int16_t *pcm = get_next_audio_frame();
const pv_status_t status = pv_picovoice_process(handle, pcm);
if (status != PV_STATUS_SUCCESS) {
// error handling logic
}
}
最后,完成时请务必释放所获取的资源。
pv_picovoice_delete(handle);
微控制器
Picovoice 使用 ANSI C 实现,因此可以将其直接链接到嵌入式 C 项目。其公共头文件包含相关信息。Picovoice 对象的实例可以按照以下方式构建。
#define MEMORY_BUFFER_SIZE ...
static uint8_t memory_buffer[MEMORY_BUFFER_SIZE] __attribute__((aligned(16)));
static const uint8_t *keyword_array = ...
const float porcupine_sensitivity = 0.5f
static void wake_word_callback(void) {
// logic to execute upon detection of wake word
}
static const uint8_t *context_array = ...
const float rhino_sensitivity = 0.75f
static void inference_callback(pv_inference_t *inference) {
// `inference` exposes three immutable properties:
// (1) `IsUnderstood`
// (2) `Intent`
// (3) `Slots`
// ..
pv_inference_delete(inference);
}
pv_picovoice_t *handle = NULL;
const pv_status_t status = pv_picovoice_init(
MEMORY_BUFFER_SIZE,
memory_buffer,
sizeof(keyword_array),
keyword_array,
porcupine_sensitivity,
wake_word_callback,
sizeof(context_array),
context_array,
rhino_sensitivity,
inference_callback,
&handle);
if (status != PV_STATUS_SUCCESS) {
// error handling logic
}
敏感性是允许开发人员以误报率为代价,权衡漏报率的参数。它是一个 [0, 1] 范围内的浮点数。更高的敏感性可以降低误报率(假拒绝率),但会增加误报率。
handle
是 Picovoice 运行时引擎的实例,用于检测在 keyword_array
中定义的唤醒词。检测到唤醒词时,它将根据在 context_array
中定义的上下文开始推断用户的意图。在检测到唤醒词时调用 wake_word_callback
,在完成后续语音命令推断时调用 inference_callback
。
Picovoice 接受单个通道、16 位 PCM 音频。可以使用 pv_sample_rate()
获取采样率。最后,Picovoice 以连续的块(称为帧)的形式接受输入音频,可以使用 pv_porcupine_frame_length()
获取帧的长度。
extern const int16_t *get_next_audio_frame(void);
while (true) {
const int16_t *pcm = get_next_audio_frame();
const pv_status_t status = pv_picovoice_process(handle, pcm);
if (status != PV_STATUS_SUCCESS) {
// error handling logic
}
}
最后,完成时请务必释放所获取的资源。
pv_picovoice_delete(handle);
发布
v2.2.0 - 2023年4月12日
- 增加了对阿拉伯语、荷兰语、印地语、普通话、波兰语、俄语、瑞典语和越南语的支持。
- 增加了对 .NET 7.0 的支持,并修复了对 .NET Standard 2.0 的支持。
- 将 iOS 最低支持版本升级到 11.0。
- 提高了稳定性和性能。
v2.1.0 - 2022年1月20日
- 为 Java 和 Unity SDK 增加了 macOS arm64 (Apple Silicon) 支持。
- 各种错误修复和改进。
v2.0.0 - 2021年11月25日
- 提高了准确性。
- 增加了 Rust SDK。
- 支持 macOS arm64。
- 为 Windows、NVIDIA Jetson Nano 和 BeagleBone 添加了 NodeJS 支持。
- 为 NVIDIA Jetson Nano 和 BeagleBone 添加了 .NET 支持。
- 运行时优化。
v1.1.0 - 2020年12月2日
- 提高了准确性。
- 运行时优化。
- .NET SDK。
- Java SDK。
- React Native SDK。
- C SDK。
v1.0.0 - 2020年10月22日
- 首次发布。
常见问题解答(FAQ)
您可以在此处找到常见问题解答。