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

在这里插入图片描述

http://www.lryc.cn/news/301725.html

相关文章:

  • typeScript 类型推论
  • JavaScript 设计模式之代理模式
  • JavaScript 对象判断
  • Android下SF合成流程重学习之onMessageInvalidate
  • 基于SpringBoot+WebSocket+Spring Task的前后端分离外卖项目-订单管理(十七)
  • 【Java多线程进阶】JUC常见类以及CAS机制
  • Python算法100例-1.7 最佳存款方案
  • ADO世界之FIRST
  • 【COMP337 LEC 5-6】
  • 力扣72. 编辑距离(动态规划)
  • linux tree命令找不到:如何使用Linux Tree命令查看文件系统结构
  • OJ_最大逆序差
  • MyBatis-Plus 实体类里写正则让字段phone限制为手机格式
  • K8S之运用污点、容忍度设置Pod的调度约束
  • Sora爆火,普通人的10个赚钱机会
  • 【C++】C++入门—初识构造函数 , 析构函数,拷贝构造函数,赋值运算符重载
  • 沁恒CH32V30X学习笔记04--外部中断
  • 基础IO[三]
  • Leetcode 392 判断子序列
  • 基于微信小程序的校园跑腿系统的研究与实现,附源码
  • VTK Python PyQt 监听键盘 控制 Actor 移动 变色
  • 力扣 第 124 场双周赛 解题报告 | 珂学家 | 非常规区间合并
  • 2024年华为OD机试真题-生成哈夫曼树-Java-OD统一考试(C卷)
  • 【实战】二、Jest难点进阶(二) —— 前端要学的测试课 从Jest入门到TDD BDD双实战(六)
  • (一)【Jmeter】JDK及Jmeter的安装部署及简单配置
  • HAL/LL/STD STM32 U8g2库 +I2C SSD1306/sh1106 WouoUI磁贴案例
  • 手机如何改自己的ip地址
  • ajax函数库axios基本使用
  • 【nginx实践连载-4】彻底卸载Nginx(Ubuntu)
  • 究极小白如何自己搭建一个自动发卡网站-独角数卡