diff --git a/speech_recognition/__init__.py b/speech_recognition/__init__.py index 37d5f49e..2169ae57 100644 --- a/speech_recognition/__init__.py +++ b/speech_recognition/__init__.py @@ -21,7 +21,7 @@ import uuid __author__ = "Anthony Zhang (Uberi)" -__version__ = "3.6.4" +__version__ = "3.6.5" __license__ = "BSD" try: # attempt to use the Python 2 modules @@ -1105,7 +1105,7 @@ def __enter__(self): # create the temporary file and open it import tempfile file_descriptor, file_path = tempfile.mkstemp() - self._file = open(file_descriptor, self.mode) + self._file = os.fdopen(file_descriptor, self.mode) # the name property is a public field self.name = file_path diff --git a/tests/test_special_features.py b/tests/test_special_features.py new file mode 100644 index 00000000..c77ab44a --- /dev/null +++ b/tests/test_special_features.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os +import unittest + +import speech_recognition as sr + + +class TestSpecialFeatures(unittest.TestCase): + def setUp(self): + self.AUDIO_FILE_EN = os.path.join(os.path.dirname(os.path.realpath(__file__)), "english.wav") + + 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 ") + + +if __name__ == "__main__": + unittest.main()