语音唤醒——
文章目录
- 配置
- 主代码
- 参考文档:https://picovoice.ai/docs/quick-start/porcupine-python/
配置
pip install pvporcupine
主代码
ACCESS_KEY:需要将该参数填入即可
#
# Copyright 2018-2023 Picovoice Inc.
#
# You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
# file accompanying this source.
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#import argparse
import os
import struct
import wave
from datetime import datetimeimport pvporcupine
from pvrecorder import PvRecorder# ##################################################### #
ACCESS_KEY = 'xxxx' # 更换成自己的
# ##################################################### ## pvporcupine.KEYWORDS
print(f"Keywords: {pvporcupine.KEYWORDS}")def main():parser = argparse.ArgumentParser()parser.add_argument('--access_key',default=ACCESS_KEY,help='AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)')parser.add_argument('--keywords',nargs='+',help='List of default keywords for detection. Available keywords: %s' % ', '.join('%s' % w for w in sorted(pvporcupine.KEYWORDS)),# choices=sorted(pvporcupine.KEYWORDS),default=['pico clock', 'picovoice', 'ok google', 'americano', 'hey barista', 'alexa', 'grasshopper', 'blueberry', 'hey siri', 'jarvis', 'porcupine', 'terminator', 'grapefruit', 'computer', 'hey google', 'bumblebee'],metavar='')parser.add_argument('--keyword_paths',nargs='+',help="Absolute paths to keyword model files. If not set it will be populated from `--keywords` argument")parser.add_argument('--library_path',help='Absolute path to dynamic library. Default: using the library provided by `pvporcupine`')parser.add_argument('--model_path',help='Absolute path to the file containing model parameters. ''Default: using the library provided by `pvporcupine`')parser.add_argument('--sensitivities',nargs='+',help="Sensitivities for detecting keywords. Each value should be a number within [0, 1]. A higher ""sensitivity results in fewer misses at the cost of increasing the false alarm rate. If not set 0.5 ""will be used.",type=float,default=None)parser.add_argument('--audio_device_index', help='Index of input audio device.', type=int, default=-1)parser.add_argument('--output_path', help='Absolute path to recorded audio for debugging.', default=None)parser.add_argument('--show_audio_devices', action='store_true')args = parser.parse_args()if args.show_audio_devices:for i, device in enumerate(PvRecorder.get_available_devices()):print('Device %d: %s' % (i, device))returnif args.keyword_paths is None:if args.keywords is None:raise ValueError("Either `--keywords` or `--keyword_paths` must be set.")keyword_paths = [pvporcupine.KEYWORD_PATHS[x] for x in args.keywords]else:keyword_paths = args.keyword_pathsprint(f"keyword_paths: {keyword_paths}")print(f"model_path: {args.model_path}")if args.sensitivities is None:args.sensitivities = [0.5] * len(keyword_paths)if len(keyword_paths) != len(args.sensitivities):raise ValueError('Number of keywords does not match the number of sensitivities.')try:porcupine = pvporcupine.create(access_key=args.access_key,library_path=args.library_path,model_path=args.model_path,keyword_paths=keyword_paths,sensitivities=args.sensitivities)except pvporcupine.PorcupineInvalidArgumentError as e:print("One or more arguments provided to Porcupine is invalid: ", args)print(e)raise eexcept pvporcupine.PorcupineActivationError as e:print("AccessKey activation error")raise eexcept pvporcupine.PorcupineActivationLimitError as e:print("AccessKey '%s' has reached it's temporary device limit" % args.access_key)raise eexcept pvporcupine.PorcupineActivationRefusedError as e:print("AccessKey '%s' refused" % args.access_key)raise eexcept pvporcupine.PorcupineActivationThrottledError as e:print("AccessKey '%s' has been throttled" % args.access_key)raise eexcept pvporcupine.PorcupineError as e:print("Failed to initialize Porcupine")raise ekeywords = list()for x in keyword_paths:keyword_phrase_part = os.path.basename(x).replace('.ppn', '').split('_')if len(keyword_phrase_part) > 6:keywords.append(' '.join(keyword_phrase_part[0:-6]))else:keywords.append(keyword_phrase_part[0])print('Porcupine version: %s' % porcupine.version)recorder = PvRecorder(frame_length=porcupine.frame_length,device_index=args.audio_device_index)recorder.start()wav_file = Noneif args.output_path is not None:wav_file = wave.open(args.output_path, "w")wav_file.setnchannels(1)wav_file.setsampwidth(2)wav_file.setframerate(16000)print('Listening ... (press Ctrl+C to exit)')try:while True:pcm = recorder.read()result = porcupine.process(pcm)if wav_file is not None:wav_file.writeframes(struct.pack("h" * len(pcm), *pcm))if result >= 0:print('[%s] Detected %s' % (str(datetime.now()), keywords[result]))except KeyboardInterrupt:print('Stopping ...')finally:recorder.delete()porcupine.delete()if wav_file is not None:wav_file.close()if __name__ == '__main__':main()
在ARM硬件RV328上,双核Contax A53,平均延时2ms。

相关文章:
语音唤醒——
文章目录 配置主代码 参考文档:https://picovoice.ai/docs/quick-start/porcupine-python/ 配置 pip install pvporcupine主代码 ACCESS_KEY:需要将该参数填入即可 # # Copyright 2018-2023 Picovoice Inc. # # You may not use this file except in …...
typeScript 类型推论
什么是类型推论? 类型推论是 TypeScript 中的一个特性,它允许开发人员不必显式地指定变量的类型。相反,开发人员可以根据变量的使用情况让 TypeScript 编译器自动推断出类型。例如,如果开发人员将一个字符串赋值给一个变量&#…...
JavaScript 设计模式之代理模式
代理模式 其实这种模式在现在很多地方也都有使用到,如 Vue3 中的数据相应原理就是使用的 es6 中的 Proxy 代理及 Reflect 反射的方式来处理数据响应式 我们日常在使用数据请求时,也会用到一些代理的方式,比如在请求不同的域名,端…...
JavaScript 对象判断
如何判断一个对象是否是Set、Map、Array、Object 参考链接: https://blog.csdn.net/yunchong_zhao/article/details/115915624 let set new Set() let map new Map() let arr [] let obj {}console.log(Object.prototype.toString.call(obj)); // [object Obje…...
Android下SF合成流程重学习之onMessageInvalidate
Android下SF合成流程重学习之onMessageInvalidate 引言 虽然看了很多关于Android Graphics图形栈的文章和博客,但是都没有形成自己的知识点。每次学习了,仅仅是学习了而已,没有形成自己的知识体系,这次趁着有时间,这次…...
基于SpringBoot+WebSocket+Spring Task的前后端分离外卖项目-订单管理(十七)
订单管理 1. Spring Task1.1 介绍1.2 cron表达式1.3 入门案例1.3.1 Spring Task使用步骤1.3.2 代码开发1.3.3 功能测试 2.订单状态定时处理2.1 需求分析2.2 代码开发2.3 功能测试 3. WebSocket3.1 介绍3.2 入门案例3.2.1 案例分析3.2.2 代码开发3.2.3 功能测试 4. 来单提醒4.1 …...
【Java多线程进阶】JUC常见类以及CAS机制
1. Callable的用法 之前已经接触过了Runnable接口,即我们可以使用实现Runnable接口的方式创建一个线程,而Callable也是一个interface,我们也可以用Callable来创建一个线程。 Callable是一个带有泛型的interface实现Callable接口必须重写cal…...
Python算法100例-1.7 最佳存款方案
完整源代码项目地址,关注博主私信’源代码’后可获取 1.问题描述2.问题分析3.算法设计4.完整的程序 1.问题描述 假设银行一年整存零取的月息为0.63%。现在某人手中有一笔钱,他打算在今后5年中的每年年底取出1000元,到第5年时刚…...
ADO世界之FIRST
目录 一、ADO 简介 二、ADO 数据库连接 1.创建一个 DSN-less 数据库连接 2.创建一个 ODBC 数据库连接 3.到 MS Access 数据库的 ODBC 连接 4.ADO 连接对象(ADO Connection Object) 三、ADO Recordset(记录集) 1.创建一个 …...
【COMP337 LEC 5-6】
LEC 5 Perceptron : Binary Classification Algorithm 8 感应器是 单个神经元的模型 突触连接的强度取决于接受外部刺激的反应 X input W weights a x1*w1x2*w2....... > / < threshold Bias MaxIter is a hyperparameter 超参数 which has to be chosen…...
力扣72. 编辑距离(动态规划)
Problem: 72. 编辑距离 文章目录 题目描述思路复杂度Code 题目描述 思路 由于易得将字符串word1向word2转换和word2向word1转换是等效的,则我们假定统一为word1向word2转换!!! 1.确定状态:我们假设现在有下标i&#x…...
linux tree命令找不到:如何使用Linux Tree命令查看文件系统结构
Linux tree命令是一个用于显示文件夹和文件的结构的工具,它可以帮助用户更好地理解文件系统的结构。如果你在linux系统上找不到tree命令,那么可能是因为你的系统中没有安装tree命令。 解决方案 Linux tree命令是一个用于显示文件夹和文件的结构的工具&…...
OJ_最大逆序差
题目 给定一个数组,编写一个算法找出这个数组中最大的逆序差。逆序差就是i<j时,a[j]-a[i]的值 c语言实现 #include <stdio.h> #include <limits.h> // 包含INT_MIN定义 int maxReverseDifference(int arr[], int size) { if (size…...
MyBatis-Plus 实体类里写正则让字段phone限制为手机格式
/* Copyright © 2021User:啾啾修车File:ToupiaoRecord.javaDate:2021/01/12 19:29:12 */ package com.jjsos.repair.toupiao.entity; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomido…...
K8S之运用污点、容忍度设置Pod的调度约束
污点、容忍度 污点容忍度 taints 是键值数据,用在节点上,定义污点; tolerations 是键值数据,用在pod上,定义容忍度,能容忍哪些污点。 污点 污点是定义在k8s集群的节点上的键值属性数据,可以决…...
Sora爆火,普通人的10个赚钱机会
您好,我是码农飞哥(wei158556),感谢您阅读本文,欢迎一键三连哦。💪🏻 1. Python基础专栏,基础知识一网打尽,9.9元买不了吃亏,买不了上当。 Python从入门到精通…...
【C++】C++入门—初识构造函数 , 析构函数,拷贝构造函数,赋值运算符重载
C入门 六个默认成员函数1 构造函数语法特性 2 析构函数语法特性 3 拷贝构造函数特性 4 赋值运算符重载运算符重载赋值运算符重载特例:前置 与 后置前置:返回1之后的结果后置: Thanks♪(・ω・)ノ谢谢阅读&…...
沁恒CH32V30X学习笔记04--外部中断
外部中断 CH32V2x 和 CH32V3x 系列内置可编程快速中断控制器(PFIC– Programmable Fast Interrupt Controller),最多支持 255 个中断向量。当前系统管理了 88 个外设中断通道和 8 个内核中断通道 PFIC 控制器 88个外设中断,每个中断请求都有独立的触发和屏蔽控制位,有专…...
基础IO[三]
close关闭之后文件内部没有数据, stdout和stderr 他们一起重定向,只会重定向号文件描述符,因为一号和二号描述符虽然都是sydout,但是并不一样,而是相当于一个显示器被打开了2次。 分别重定向到2个文件的写法和直接写道…...
Leetcode 392 判断子序列
题意理解: 给定字符串 s 和 t ,判断 s 是否为 t 的子序列。 字符串的一个子序列是原始字符串删除一些(也可以不删除)字符而不改变剩余字符相对位置形成的新字符串。(例如,"ace"是"abcde&quo…...
XCTF-web-easyupload
试了试php,php7,pht,phtml等,都没有用 尝试.user.ini 抓包修改将.user.ini修改为jpg图片 在上传一个123.jpg 用蚁剑连接,得到flag...
应用升级/灾备测试时使用guarantee 闪回点迅速回退
1.场景 应用要升级,当升级失败时,数据库回退到升级前. 要测试系统,测试完成后,数据库要回退到测试前。 相对于RMAN恢复需要很长时间, 数据库闪回只需要几分钟。 2.技术实现 数据库设置 2个db_recovery参数 创建guarantee闪回点,不需要开启数据库闪回。…...
【决胜公务员考试】求职OMG——见面课测验1
2025最新版!!!6.8截至答题,大家注意呀! 博主码字不易点个关注吧,祝期末顺利~~ 1.单选题(2分) 下列说法错误的是:( B ) A.选调生属于公务员系统 B.公务员属于事业编 C.选调生有基层锻炼的要求 D…...
Python如何给视频添加音频和字幕
在Python中,给视频添加音频和字幕可以使用电影文件处理库MoviePy和字幕处理库Subtitles。下面将详细介绍如何使用这些库来实现视频的音频和字幕添加,包括必要的代码示例和详细解释。 环境准备 在开始之前,需要安装以下Python库:…...
优选算法第十二讲:队列 + 宽搜 优先级队列
优选算法第十二讲:队列 宽搜 && 优先级队列 1.N叉树的层序遍历2.二叉树的锯齿型层序遍历3.二叉树最大宽度4.在每个树行中找最大值5.优先级队列 -- 最后一块石头的重量6.数据流中的第K大元素7.前K个高频单词8.数据流的中位数 1.N叉树的层序遍历 2.二叉树的锯…...
Spring是如何解决Bean的循环依赖:三级缓存机制
1、什么是 Bean 的循环依赖 在 Spring框架中,Bean 的循环依赖是指多个 Bean 之间互相持有对方引用,形成闭环依赖关系的现象。 多个 Bean 的依赖关系构成环形链路,例如: 双向依赖:Bean A 依赖 Bean B,同时 Bean B 也依赖 Bean A(A↔B)。链条循环: Bean A → Bean…...
使用LangGraph和LangSmith构建多智能体人工智能系统
现在,通过组合几个较小的子智能体来创建一个强大的人工智能智能体正成为一种趋势。但这也带来了一些挑战,比如减少幻觉、管理对话流程、在测试期间留意智能体的工作方式、允许人工介入以及评估其性能。你需要进行大量的反复试验。 在这篇博客〔原作者&a…...
群晖NAS如何在虚拟机创建飞牛NAS
套件中心下载安装Virtual Machine Manager 创建虚拟机 配置虚拟机 飞牛官网下载 https://iso.liveupdate.fnnas.com/x86_64/trim/fnos-0.9.2-863.iso 群晖NAS如何在虚拟机创建飞牛NAS - 个人信息分享...
Xcode 16 集成 cocoapods 报错
基于 Xcode 16 新建工程项目,集成 cocoapods 执行 pod init 报错 ### Error RuntimeError - PBXGroup attempted to initialize an object with unknown ISA PBXFileSystemSynchronizedRootGroup from attributes: {"isa">"PBXFileSystemSynchro…...
CSS 工具对比:UnoCSS vs Tailwind CSS,谁是你的菜?
在现代前端开发中,Utility-First (功能优先) CSS 框架已经成为主流。其中,Tailwind CSS 无疑是市场的领导者和标杆。然而,一个名为 UnoCSS 的新星正以其惊人的性能和极致的灵活性迅速崛起。 这篇文章将深入探讨这两款工具的核心理念、技术差…...
