Skip to content

Commit

Permalink
Merge pull request #418 from native-api/fix_build
Browse files Browse the repository at this point in the history
Fix Travis build
  • Loading branch information
Uberi authored Jul 2, 2019
2 parents 350397d + 7e7902b commit c898560
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ addons:
packages:
- swig
- libpulse-dev
- libasound2-dev
install:
- trap 'sleep 3' ERR
- pip install pocketsphinx monotonic
- pip install flake8 rstcheck
- pip install -e .
script:
- flake8 --ignore=E501,E701 speech_recognition tests examples setup.py # ignore errors for long lines and multi-statement lines
- flake8 --ignore=E501,E701,W504 speech_recognition tests examples setup.py # ignore errors for long lines and multi-statement lines
- rstcheck README.rst reference/*.rst # ensure RST is well-formed
- python -m unittest discover --verbose # run unit tests
sudo: false # this allows TravisCI to use the fast Docker build environment rather than the slower VMs
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Note that the versions available in most package repositories are outdated and w
See `Notes on using PocketSphinx <https://github.com/Uberi/speech_recognition/blob/master/reference/pocketsphinx.rst>`__ for information about installing languages, compiling PocketSphinx, and building language packs from online resources. This document is also included under ``reference/pocketsphinx.rst``.

Google Cloud Speech Library for Python (for Google Cloud Speech API users)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`Google Cloud Speech library for Python <https://cloud.google.com/speech-to-text/docs/quickstart>`__ is required if and only if you want to use the Google Cloud Speech API (``recognizer_instance.recognize_google_cloud``).

Expand Down
2 changes: 1 addition & 1 deletion reference/library-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ Returns the most likely transcription if ``show_all`` is false (the default). Ot
Raises a ``speech_recognition.UnknownValueError`` exception if the speech is unintelligible. Raises a ``speech_recognition.RequestError`` exception if there are any issues with the Sphinx installation.

``recognizer_instance.recognize_google(audio_data: AudioData, key: Union[str, None] = None, language: str = "en-US", , pfilter: Union[0, 1], show_all: bool = False) -> Union[str, Dict[str, Any]]``
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Performs speech recognition on ``audio_data`` (an ``AudioData`` instance), using the Google Speech Recognition API.

Expand Down
4 changes: 2 additions & 2 deletions speech_recognition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def recognize_sphinx(self, audio_data, language="en-US", keyword_entries=None, g
fsg = FsgModel(fsg_path, decoder.get_logmath(), 7.5)
decoder.set_fsg(grammar_name, fsg)
decoder.set_search(grammar_name)

decoder.start_utt() # begin utterance processing
decoder.process_raw(raw_data, False, True) # process audio data with recognition enabled (no_search = False), as a full utterance (full_utt = True)
decoder.end_utt() # stop utterance processing
Expand Down Expand Up @@ -957,7 +957,7 @@ def recognize_google_cloud(self, audio_data, credentials_json=None, language="en
phrases=preferred_phrases
)]
if show_all:
config['enableWordTimeOffsets'] = True # some useful extra options for when we want all the output
config['enableWordTimeOffsets'] = True # some useful extra options for when we want all the output

opts = {}
if self.operation_timeout and socket.getdefaulttimeout() is None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def setUp(self):
def test_sphinx_english(self):
r = sr.Recognizer()
with sr.AudioFile(self.AUDIO_FILE_EN) as source: audio = r.record(source)
self.assertEqual(r.recognize_sphinx(audio), "wanted to three")
self.assertEqual(r.recognize_sphinx(audio), "one two three")

def test_google_english(self):
r = sr.Recognizer()
Expand Down
13 changes: 10 additions & 3 deletions tests/test_special_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@
class TestSpecialFeatures(unittest.TestCase):
def setUp(self):
self.AUDIO_FILE_EN = os.path.join(os.path.dirname(os.path.realpath(__file__)), "english.wav")
self.addTypeEqualityFunc(str, self.assertSameWords)

def test_sphinx_keywords(self):
r = sr.Recognizer()
with sr.AudioFile(self.AUDIO_FILE_EN) as source: audio = r.record(source)
self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("one", 1.0), ("two", 1.0), ("three", 1.0)]), "three two two one ")
self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("wan", 0.95), ("too", 1.0), ("tree", 1.0)]), "tree too wan too wan ")
self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("un", 0.95), ("to", 1.0), ("tee", 1.0)]), "tee to un to un un un ")
self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("one", 1.0), ("two", 1.0), ("three", 1.0)]), "three two one")
self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("wan", 0.95), ("too", 1.0), ("tree", 1.0)]), "tree too wan")
self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("un", 0.95), ("to", 1.0), ("tee", 1.0)]), "tee to un")

def assertSameWords(self, tested, reference, msg=None):
set_tested = set(tested.split())
set_reference = set(reference.split())
if set_tested != set_reference:
raise self.failureException(msg if msg is not None else "%r doesn't consist of the same words as %r" % (tested, reference))


if __name__ == "__main__":
Expand Down

0 comments on commit c898560

Please sign in to comment.