当前位置: 首页 > news >正文

语音唤醒——

文章目录

    • 配置
    • 主代码

  • 参考文档: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 &#xff1a; 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转换是等效的&#xff0c;则我们假定统一为word1向word2转换&#xff01;&#xff01;&#xff01; 1.确定状态&#xff1a;我们假设现在有下标i&#x…...

linux tree命令找不到:如何使用Linux Tree命令查看文件系统结构

Linux tree命令是一个用于显示文件夹和文件的结构的工具&#xff0c;它可以帮助用户更好地理解文件系统的结构。如果你在linux系统上找不到tree命令&#xff0c;那么可能是因为你的系统中没有安装tree命令。 解决方案 Linux tree命令是一个用于显示文件夹和文件的结构的工具&…...

OJ_最大逆序差

题目 给定一个数组&#xff0c;编写一个算法找出这个数组中最大的逆序差。逆序差就是i<j时&#xff0c;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 是键值数据&#xff0c;用在节点上&#xff0c;定义污点&#xff1b; tolerations 是键值数据&#xff0c;用在pod上&#xff0c;定义容忍度&#xff0c;能容忍哪些污点。 污点 污点是定义在k8s集群的节点上的键值属性数据&#xff0c;可以决…...

Sora爆火,普通人的10个赚钱机会

您好&#xff0c;我是码农飞哥&#xff08;wei158556&#xff09;&#xff0c;感谢您阅读本文&#xff0c;欢迎一键三连哦。&#x1f4aa;&#x1f3fb; 1. Python基础专栏&#xff0c;基础知识一网打尽&#xff0c;9.9元买不了吃亏&#xff0c;买不了上当。 Python从入门到精通…...

【C++】C++入门—初识构造函数 , 析构函数,拷贝构造函数,赋值运算符重载

C入门 六个默认成员函数1 构造函数语法特性 2 析构函数语法特性 3 拷贝构造函数特性 4 赋值运算符重载运算符重载赋值运算符重载特例&#xff1a;前置 与 后置前置&#xff1a;返回1之后的结果后置&#xff1a; Thanks♪(&#xff65;ω&#xff65;)&#xff89;谢谢阅读&…...

沁恒CH32V30X学习笔记04--外部中断

外部中断 CH32V2x 和 CH32V3x 系列内置可编程快速中断控制器(PFIC– Programmable Fast Interrupt Controller),最多支持 255 个中断向量。当前系统管理了 88 个外设中断通道和 8 个内核中断通道 PFIC 控制器 88个外设中断,每个中断请求都有独立的触发和屏蔽控制位,有专…...

基础IO[三]

close关闭之后文件内部没有数据&#xff0c; stdout和stderr 他们一起重定向&#xff0c;只会重定向号文件描述符&#xff0c;因为一号和二号描述符虽然都是sydout&#xff0c;但是并不一样&#xff0c;而是相当于一个显示器被打开了2次。 分别重定向到2个文件的写法和直接写道…...

Leetcode 392 判断子序列

题意理解&#xff1a; 给定字符串 s 和 t &#xff0c;判断 s 是否为 t 的子序列。 字符串的一个子序列是原始字符串删除一些&#xff08;也可以不删除&#xff09;字符而不改变剩余字符相对位置形成的新字符串。&#xff08;例如&#xff0c;"ace"是"abcde&quo…...

iOS 26 携众系统重磅更新,但“苹果智能”仍与国行无缘

美国西海岸的夏天&#xff0c;再次被苹果点燃。一年一度的全球开发者大会 WWDC25 如期而至&#xff0c;这不仅是开发者的盛宴&#xff0c;更是全球数亿苹果用户翘首以盼的科技春晚。今年&#xff0c;苹果依旧为我们带来了全家桶式的系统更新&#xff0c;包括 iOS 26、iPadOS 26…...

智慧医疗能源事业线深度画像分析(上)

引言 医疗行业作为现代社会的关键基础设施,其能源消耗与环境影响正日益受到关注。随着全球"双碳"目标的推进和可持续发展理念的深入,智慧医疗能源事业线应运而生,致力于通过创新技术与管理方案,重构医疗领域的能源使用模式。这一事业线融合了能源管理、可持续发…...

Spark 之 入门讲解详细版(1)

1、简介 1.1 Spark简介 Spark是加州大学伯克利分校AMP实验室&#xff08;Algorithms, Machines, and People Lab&#xff09;开发通用内存并行计算框架。Spark在2013年6月进入Apache成为孵化项目&#xff0c;8个月后成为Apache顶级项目&#xff0c;速度之快足见过人之处&…...

解决Ubuntu22.04 VMware失败的问题 ubuntu入门之二十八

现象1 打开VMware失败 Ubuntu升级之后打开VMware上报需要安装vmmon和vmnet&#xff0c;点击确认后如下提示 最终上报fail 解决方法 内核升级导致&#xff0c;需要在新内核下重新下载编译安装 查看版本 $ vmware -v VMware Workstation 17.5.1 build-23298084$ lsb_release…...

Python爬虫实战:研究feedparser库相关技术

1. 引言 1.1 研究背景与意义 在当今信息爆炸的时代,互联网上存在着海量的信息资源。RSS(Really Simple Syndication)作为一种标准化的信息聚合技术,被广泛用于网站内容的发布和订阅。通过 RSS,用户可以方便地获取网站更新的内容,而无需频繁访问各个网站。 然而,互联网…...

在 Nginx Stream 层“改写”MQTT ngx_stream_mqtt_filter_module

1、为什么要修改 CONNECT 报文&#xff1f; 多租户隔离&#xff1a;自动为接入设备追加租户前缀&#xff0c;后端按 ClientID 拆分队列。零代码鉴权&#xff1a;将入站用户名替换为 OAuth Access-Token&#xff0c;后端 Broker 统一校验。灰度发布&#xff1a;根据 IP/地理位写…...

MVC 数据库

MVC 数据库 引言 在软件开发领域,Model-View-Controller(MVC)是一种流行的软件架构模式,它将应用程序分为三个核心组件:模型(Model)、视图(View)和控制器(Controller)。这种模式有助于提高代码的可维护性和可扩展性。本文将深入探讨MVC架构与数据库之间的关系,以…...

基础测试工具使用经验

背景 vtune&#xff0c;perf, nsight system等基础测试工具&#xff0c;都是用过的&#xff0c;但是没有记录&#xff0c;都逐渐忘了。所以写这篇博客总结记录一下&#xff0c;只要以后发现新的用法&#xff0c;就记得来编辑补充一下 perf 比较基础的用法&#xff1a; 先改这…...

sqlserver 根据指定字符 解析拼接字符串

DECLARE LotNo NVARCHAR(50)A,B,C DECLARE xml XML ( SELECT <x> REPLACE(LotNo, ,, </x><x>) </x> ) DECLARE ErrorCode NVARCHAR(50) -- 提取 XML 中的值 SELECT value x.value(., VARCHAR(MAX))…...

实现弹窗随键盘上移居中

实现弹窗随键盘上移的核心思路 在Android中&#xff0c;可以通过监听键盘的显示和隐藏事件&#xff0c;动态调整弹窗的位置。关键点在于获取键盘高度&#xff0c;并计算剩余屏幕空间以重新定位弹窗。 // 在Activity或Fragment中设置键盘监听 val rootView findViewById<V…...