Skip to content

Commit d9e6e3a

Browse files
committed
Fix bing recognition, add Amazon Lex (though not documented yet, README fixes)
1 parent 8740a7a commit d9e6e3a

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ The "bt_audio_service_open" error means that you have a Bluetooth audio device,
254254

255255
For errors of the form "ALSA lib [...] Unknown PCM", see `this StackOverflow answer <http://stackoverflow.com/questions/7088672/pyaudio-working-but-spits-out-error-messages-each-time>`__. Basically, to get rid of an error of the form "Unknown PCM cards.pcm.rear", simply comment out ``pcm.rear cards.pcm.rear`` in ``/usr/share/alsa/alsa.conf``, ``~/.asoundrc``, and ``/etc/asound.conf``.
256256

257-
For "jack server is not running or cannot be started" or "connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)" or "attempt to connect to server failed", these are caused by ALSA trying to connect to JACK, and can be safely ignored. I'm not aware of any simple way to turn those messages off at this time, besides [entirely disabling printing while starting the microphone](https://github.com/Uberi/speech_recognition/issues/182#issuecomment-266256337).
257+
For "jack server is not running or cannot be started" or "connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)" or "attempt to connect to server failed", these are caused by ALSA trying to connect to JACK, and can be safely ignored. I'm not aware of any simple way to turn those messages off at this time, besides `entirely disabling printing while starting the microphone <https://github.com/Uberi/speech_recognition/issues/182#issuecomment-266256337>`__.
258258

259259
On OS X, I get a ``ChildProcessError`` saying that it couldn't find the system FLAC converter, even though it's installed.
260260
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

make-release.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ set -o pipefail # for a pipeline, if any of the commands fail with a non-zero ex
88
echo "Making release for SpeechRecognition-$1"
99

1010
python setup.py bdist_wheel
11-
gpg2 --detach-sign -a dist/SpeechRecognition-$1-*.whl
11+
gpg --detach-sign -a dist/SpeechRecognition-$1-*.whl
1212
twine upload dist/SpeechRecognition-$1-*.whl dist/SpeechRecognition-$1-*.whl.asc

speech_recognition/__init__.py

+34
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,40 @@ def recognize_bing(self, audio_data, key, language="en-US", show_all=False):
11081108
if "RecognitionStatus" not in result or result["RecognitionStatus"] != "Success" or "DisplayText" not in result: raise UnknownValueError()
11091109
return result["DisplayText"]
11101110

1111+
def recognize_lex(self, audio_data, bot_name, bot_alias, user_id, content_type="audio/l16; rate=16000; channels=1", access_key_id=None, secret_access_key=None, region=None):
1112+
"""
1113+
Performs speech recognition on ``audio_data`` (an ``AudioData`` instance), using the Amazon Lex API.
1114+
1115+
If access_key_id or secret_access_key is not set it will go through the list in the link below
1116+
http://boto3.readthedocs.io/en/latest/guide/configuration.html#configuring-credentials
1117+
"""
1118+
assert isinstance(audio_data, AudioData), "Data must be audio data"
1119+
assert isinstance(bot_name, str), "``bot_name`` must be a string"
1120+
assert isinstance(bot_alias, str), "``bot_alias`` must be a string"
1121+
assert isinstance(user_id, str), "``user_id`` must be a string"
1122+
assert isinstance(content_type, str), "``content_type`` must be a string"
1123+
assert access_key_id is None or isinstance(access_key_id, str), "``access_key_id`` must be a string"
1124+
assert secret_access_key is None or isinstance(secret_access_key, str), "``secret_access_key`` must be a string"
1125+
assert region is None or isinstance(region, str), "``region`` must be a string"
1126+
1127+
try:
1128+
import boto3
1129+
except ImportError:
1130+
raise RequestError("missing boto3 module: ensure that boto3 is set up correctly.")
1131+
1132+
client = boto3.client('lex-runtime', aws_access_key_id=access_key_id,
1133+
aws_secret_access_key=secret_access_key,
1134+
region_name=region)
1135+
1136+
raw_data = audio_data.get_raw_data(
1137+
convert_rate=16000, convert_width=2
1138+
)
1139+
1140+
accept = "text/plain; charset=utf-8"
1141+
response = client.post_content(botName=bot_name, botAlias=bot_alias, userId=user_id, contentType=content_type, accept=accept, inputStream=raw_data)
1142+
1143+
return response["inputTranscript"]
1144+
11111145
def recognize_houndify(self, audio_data, client_id, client_key, show_all=False):
11121146
"""
11131147
Performs speech recognition on ``audio_data`` (an ``AudioData`` instance), using the Houndify API.

0 commit comments

Comments
 (0)