当前位置: 首页 > 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…...

论文解读:交大港大上海AI Lab开源论文 | 宇树机器人多姿态起立控制强化学习框架(二)

HoST框架核心实现方法详解 - 论文深度解读(第二部分) 《Learning Humanoid Standing-up Control across Diverse Postures》 系列文章: 论文深度解读 + 算法与代码分析(二) 作者机构: 上海AI Lab, 上海交通大学, 香港大学, 浙江大学, 香港中文大学 论文主题: 人形机器人…...

UDP(Echoserver)

网络命令 Ping 命令 检测网络是否连通 使用方法: ping -c 次数 网址ping -c 3 www.baidu.comnetstat 命令 netstat 是一个用来查看网络状态的重要工具. 语法&#xff1a;netstat [选项] 功能&#xff1a;查看网络状态 常用选项&#xff1a; n 拒绝显示别名&#…...

el-switch文字内置

el-switch文字内置 效果 vue <div style"color:#ffffff;font-size:14px;float:left;margin-bottom:5px;margin-right:5px;">自动加载</div> <el-switch v-model"value" active-color"#3E99FB" inactive-color"#DCDFE6"…...

土地利用/土地覆盖遥感解译与基于CLUE模型未来变化情景预测;从基础到高级,涵盖ArcGIS数据处理、ENVI遥感解译与CLUE模型情景模拟等

&#x1f50d; 土地利用/土地覆盖数据是生态、环境和气象等诸多领域模型的关键输入参数。通过遥感影像解译技术&#xff0c;可以精准获取历史或当前任何一个区域的土地利用/土地覆盖情况。这些数据不仅能够用于评估区域生态环境的变化趋势&#xff0c;还能有效评价重大生态工程…...

CVE-2020-17519源码分析与漏洞复现(Flink 任意文件读取)

漏洞概览 漏洞名称&#xff1a;Apache Flink REST API 任意文件读取漏洞CVE编号&#xff1a;CVE-2020-17519CVSS评分&#xff1a;7.5影响版本&#xff1a;Apache Flink 1.11.0、1.11.1、1.11.2修复版本&#xff1a;≥ 1.11.3 或 ≥ 1.12.0漏洞类型&#xff1a;路径遍历&#x…...

【无标题】路径问题的革命性重构:基于二维拓扑收缩色动力学模型的零点隧穿理论

路径问题的革命性重构&#xff1a;基于二维拓扑收缩色动力学模型的零点隧穿理论 一、传统路径模型的根本缺陷 在经典正方形路径问题中&#xff08;图1&#xff09;&#xff1a; mermaid graph LR A((A)) --- B((B)) B --- C((C)) C --- D((D)) D --- A A -.- C[无直接路径] B -…...

【LeetCode】算法详解#6 ---除自身以外数组的乘积

1.题目介绍 给定一个整数数组 nums&#xff0c;返回 数组 answer &#xff0c;其中 answer[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积 。 题目数据 保证 数组 nums之中任意元素的全部前缀元素和后缀的乘积都在 32 位 整数范围内。 请 不要使用除法&#xff0c;且在 O…...

全面解析网络端口:概念、分类与安全应用

在计算机网络的世界里&#xff0c;数据的传输与交互如同一场繁忙的物流运输&#xff0c;而网络端口就是其中不可或缺的 “货运码头”。无论是日常浏览网页、收发邮件&#xff0c;还是运行各类网络服务&#xff0c;都离不开网络端口的参与。本文将深入介绍网络端口的相关知识&am…...

人工智能学习09-变量作用域

人工智能学习概述—快手视频 人工智能学习09-变量作用域—快手视频...

结构性-代理模式

动态代理主要是为了处理重复创建模板代码的场景。 使用示例 public interface MyInterface {String doSomething(); }public class MyInterfaceImpl implements MyInterface{Overridepublic String doSomething() {return "接口方法dosomething";} }public class M…...