跳至主要内容

WrpSimpleTester

本文介绍如何运行文件语音识别库 Wrp 的示例程序 (WrpSimpleTester)。WrpSimpleTester 在控制台上运行,可以将音频文件转写为文本。

备注
  • 运行时需要设置在个人页面上显示的 APPKEY
警告
  • 请注意,使用语音识别会产生相应的费用

准备

按照获取方法获取源代码。将其放置在本地机器的任意目录中。

命令行界面

Usage: WrpSimpleTester <url> <audioFileName> <codec> <grammarFileNames> [<authorization>]

参数

参数说明
urlEndpoint
audioFileName音频文件路径
codec解码器
grammarFileNames语法文件名
authorizationAPPKEY

运行示例

每种编程语言的目录中都有 run.shrun.bat 文件。通过运行这些文件,可以使用以下参数执行示例程序。

参数说明
urlwss://acp-api.amivoice.com/v1/保存日志的 WebSocket 接口 endpoint
audioFileName../../audio/test.wav示例程序附带的音频文件
codec16K音频格式
grammarFileNames-a-general会話_汎用引擎的连接引擎名
authorizationAPPKEY请指定个人页面上显示的 APPKEY

运行 run 脚本

Windows 环境

双击各<编程语言>文件夹下的 run.bat 文件,可以以该文件夹为当前目录运行程序。运行时会提示输入 APPKEY。

从终端运行时,请将 Wrp/<编程语言> 设为当前目录,然后执行以下命令:

run.bat

Linux 环境

运行时,请将 Wrp/<编程语言> 设为当前目录。

chmod +x run.sh
./run.sh

输入 APPKEY

运行后会要求输入 APPKEY,请输入个人页面上显示的 APPKEY 或获取的一次性 APPKEY。

Please enter AppKey:

运行结果

会显示每种编程语言的 run 脚本处理过程。以下是 Python 的示例:

+ export PYTHONPATH=src
+ PYTHONPATH=src
+ export SSL_CERT_FILE=../../curl-ca-bundle.crt
+ SSL_CERT_FILE=../../curl-ca-bundle.crt
+ python WrpSimpleTester.py wss://acp-api.amivoice.com/v1/ ../../audio/test.wav 16K -a-general {APPKEY}

等待几秒钟后,无论使用哪种编程语言,都会得到类似以下的结果:

{"results":[{"tokens":[{"written":"\u30a2\u30c9\u30d0\u30f3\u30b9\u30c8\u30fb\u30e1\u30c7\u30a3\u30a2","confidence":1.00,"starttime":506,"endtime":1578,"spoken":"\u3042\u3069\u3070\u3093\u3059\u3068\u3081\u3067\u3043\u3042"},{"written":"\u306f","confidence":1.00,"starttime":1578,"endtime":1930,"spoken":"\u306f"},{"written":"\u3001","confidence":0.35,"starttime":1930,"endtime":2026,"spoken":"_"},{"written":"\u4eba","confidence":0.82,"starttime":2026,"endtime":2314,"spoken":"\u3072\u3068"},{"written":"\u3068","confidence":1.00,"starttime":2314,"endtime":2426,"spoken":"\u3068"},{"written":"\u6a5f\u68b0","confidence":1.00,"starttime":2426,"endtime":2826,"spoken":"\u304d\u304b\u3044"},{"written":"\u3068","confidence":1.00,"starttime":2826,"endtime":2938,"spoken":"\u3068"},{"written":"\u306e","confidence":0.97,"starttime":2938,"endtime":3082,"spoken":"\u306e"},{"written":"\u81ea\u7136","confidence":1.00,"starttime":3082,"endtime":3434,"spoken":"\u3057\u305c\u3093"},{"written":"\u306a","confidence":1.00,"starttime":3434,"endtime":3530,"spoken":"\u306a"},{"written":"\u30b3\u30df\u30e5\u30cb\u30b1\u30fc\u30b7\u30e7\u30f3","confidence":1.00,"starttime":3530,"endtime":4362,"spoken":"\u3053\u307f\u3085\u306b\u3051\u30fc\u3057\u3087\u3093"},{"written":"\u3092","confidence":1.00,"starttime":4362,"endtime":4442,"spoken":"\u3092"},{"written":"\u5b9f\u73fe","confidence":1.00,"starttime":4442,"endtime":4922,"spoken":"\u3058\u3064\u3052\u3093"},{"written":"\u3057","confidence":1.00,"starttime":4922,"endtime":5306,"spoken":"\u3057"},{"written":"\u3001","confidence":0.63,"starttime":5306,"endtime":5626,"spoken":"_"},{"written":"\u8c4a\u304b","confidence":1.00,"starttime":5626,"endtime":5994,"spoken":"\u3086\u305f\u304b"},{"written":"\u306a","confidence":1.00,"starttime":5994,"endtime":6090,"spoken":"\u306a"},{"written":"\u672a\u6765","confidence":1.00,"starttime":6090,"endtime":6490,"spoken":"\u307f\u3089\u3044"},{"written":"\u3092","confidence":1.00,"starttime":6490,"endtime":6570,"spoken":"\u3092"},{"written":"\u5275\u9020","confidence":0.96,"starttime":6570,"endtime":7050,"spoken":"\u305d\u3046\u305e\u3046"},{"written":"\u3057\u3066","confidence":1.00,"starttime":7050,"endtime":7226,"spoken":"\u3057\u3066"},{"written":"\u3044\u304f","confidence":1.00,"starttime":7226,"endtime":7418,"spoken":"\u3044\u304f"},{"written":"\u3053\u3068","confidence":0.96,"starttime":7418,"endtime":7674,"spoken":"\u3053\u3068"},{"written":"\u3092","confidence":1.00,"starttime":7674,"endtime":7722,"spoken":"\u3092"},{"written":"\u76ee\u6307\u3057","confidence":0.78,"starttime":7722,"endtime":8090,"spoken":"\u3081\u3056\u3057"},{"written":"\u307e\u3059","confidence":0.79,"starttime":8090,"endtime":8538,"spoken":"\u307e\u3059"},{"written":"\u3002","confidence":0.94,"starttime":8538,"endtime":8746,"spoken":"_"}],"confidence":0.981,"starttime":250,"endtime":8746,"tags":[],"rulename":"","text":"\u30a2\u30c9\u30d0\u30f3\u30b9\u30c8\u30fb\u30e1\u30c7\u30a3\u30a2\u306f\u3001\u4eba\u3068\u6a5f\u68b0\u3068\u306e\u81ea\u7136\u306a\u30b3\u30df\u30e5\u30cb\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u73fe\u3057\u3001\u8c4a\u304b\u306a\u672a\u6765\u3092\u5275\u9020\u3057\u3066\u3044\u304f\u3053\u3068\u3092\u76ee\u6307\u3057\u307e\u3059\u3002"}],"utteranceid":"20240720/10/0190cdba76010a30131294c4_20240720_102107","text":"\u30a2\u30c9\u30d0\u30f3\u30b9\u30c8\u30fb\u30e1\u30c7\u30a3\u30a2\u306f\u3001\u4eba\u3068\u6a5f\u68b0\u3068\u306e\u81ea\u7136\u306a\u30b3\u30df\u30e5\u30cb\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u73fe\u3057\u3001\u8c4a\u304b\u306a\u672a\u6765\u3092\u5275\u9020\u3057\u3066\u3044\u304f\u3053\u3068\u3092\u76ee\u6307\u3057\u307e\u3059\u3002","code":"","message":""}
-> アドバンスト・メディアは、人と機械との自然なコミュニケーションを実現し、豊かな未来を創造していくことを目指します。

第一行是 API 的原始响应,格式为 JSON。第二行 "->" 后面显示的是 text 字段中的语音识别结果文本。关于结果的处理,请参考语音识别结果格式