Skip to content
项目

zaf/asterisk-speech-recog

在 GitHub 查看

关于

Speech recognition script for Asterisk that uses google's speech engine.

人工智能与机器学习

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
+1
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文
==============================================
    Speech recognition script for Asterisk
==============================================

This script uses the Google Cloud Speech-to-Text API to transcribe speech and
return the transcript to the dialplan as an Asterisk channel variable.

------------
Requirements
------------
Perl          The Perl programming language
LWP::UserAgent and LWP::ConnCache (libwww-perl)
JSON          Module for manipulating JSON-formatted data
IO::Socket::SSL
flac          Free Lossless Audio Codec

A Cloud Speech-to-Text API key from Google:
https://cloud.google.com/speech-to-text
Internet access to contact Google and send audio for recognition.

------------
Installation
------------
Set $key in the AGI script you intend to install, then copy it to your agi-bin
directory, usually /var/lib/asterisk/agi-bin/. Check
/etc/asterisk/asterisk.conf to confirm the configured directory.

-----
Usage
-----
agi(speech-recog.agi,[lang],[timeout],[intkey],[NOBEEP],[rtimeout],[speechContexts])
Records from the current channel until 2 seconds of silence are detected
('timeout' sets the silence duration; -1 disables silence detection) or the
interrupt key (# by default) is pressed. Set 'intkey' to 'any' to accept all
digits, #, and *. If NOBEEP is set, no beep sound is played to indicate the
start of recording. If 'rtimeout' is set, it sets the absolute recording
timeout in milliseconds (-1 for no absolute timeout).
The 'speechContexts' argument provides hints to favor specific words and
phrases in the results. Example: [Agamemnon,Midas]
Recorded audio is sent to Google's speech recognition service, and the returned
text is assigned to the channel variable 'utterance'.
The script sets the following channel variables:

utterance  : The recognized transcript.
confidence : The API's confidence estimate between 0 and 1, when provided.
             Higher values indicate greater estimated confidence.

If no speech is recognized or an unexpected error occurs, both variables are
set to '-1'.

Recognition uses the synchronous Cloud Speech-to-Text API. Google currently
limits synchronous audio to about one minute and local-file requests to 10 MB.
See https://cloud.google.com/speech-to-text/quotas for current limits.

------------------
Command-line usage
------------------
The CLI scripts accept FLAC and WAV files:

cli/speech-recog-cli.pl -k KEY [options] <file>...

Run cli/speech-recog-cli.pl -h for all options. The default sample rate is
16000 Hz; use -r to specify the actual rate of files with a different rate.

--------
Examples
--------
Sample dialplan code for extensions.conf:

;Simple speech recognition
exten => 1234,1,Answer()
exten => 1234,n,agi(speech-recog.agi,en-US)
exten => 1234,n,Verbose(1,The text you just said is: ${utterance})
exten => 1234,n,Verbose(1,Recognition confidence: ${confidence})
exten => 1234,n,Hangup()

;Speech recognition demo also using googletts.agi for text-to-speech synthesis:
exten => 1235,1,Answer()
exten => 1235,n,agi(googletts.agi,"Say something in English, when done press the pound key.",en)
exten => 1235,n(record),agi(speech-recog.agi,en-US)
exten => 1235,n,Verbose(1,Script returned: ${confidence}, ${utterance})

;Check the recognition confidence:
exten => 1235,n,GotoIf($["${confidence}" > "0.8"]?playback:retry)

;Play back the text
exten => 1235,n(playback),agi(googletts.agi,"The text you just said was...",en)
exten => 1235,n,agi(googletts.agi,"${utterance}",en)
exten => 1235,n,goto(end)

;Retry in case speech recognition wasn't successful:
exten => 1235,n(retry),agi(googletts.agi,"Can you please repeat more clearly?",en)
exten => 1235,n,goto(record)

exten => 1235,n(fail),agi(googletts.agi,"Failed to get speech data.",en)
exten => 1235,n(end),Hangup()

;Voice dialing example
exten => 1236,1,Answer()
exten => 1236,n,agi(googletts.agi,"Please say the number you want to dial.",en)
exten => 1236,n(record),agi(speech-recog.agi,en-US)
exten => 1236,n,GotoIf($["${confidence}" > "0.8"]?success:retry)

exten => 1236,n(success),goto(${utterance},1)

exten => 1236,n(retry),agi(googletts.agi,"Can you please repeat?",en)
exten => 1236,n,goto(record)

-------------------
Supported Languages
-------------------
Language codes are BCP-47 language tags, such as en-US, fil-PH, cmn-Hans-CN,
and yue-Hant-HK. For the current list of supported languages and feature
availability, see https://cloud.google.com/speech-to-text/docs/languages.

-----------------------
Security Considerations
-----------------------
The script sends recorded voice data to Google and receives recognized text.
TLS encrypts traffic between the PBX and Google. Voice data is processed by
Google; review the Cloud Speech-to-Text documentation and applicable privacy
terms before use: https://cloud.google.com/speech-to-text/docs.

------------
Tiny version
------------
The '-tiny' scripts use HTTP::Tiny and JSON::Tiny instead of LWP::UserAgent and
JSON to reduce dependencies and startup overhead on embedded systems such as
Raspberry Pi. They expose the same AGI and CLI arguments and can replace the
normal scripts. Install HTTP::Tiny and JSON::Tiny before using them.

-------
License
-------
The speech-recog script for Asterisk is distributed under the GNU General
Public License v2. See COPYING for details.

--------
Homepage
--------
https://zaf.github.io/asterisk-speech-recog/

探索相关项目

加载中…