Skip to content

Commit

Permalink
Fix portable temporary named files on Python 2 and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
Uberi committed Apr 13, 2017
1 parent c6a583b commit 3cc29a6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions speech_recognition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions tests/test_special_features.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 3cc29a6

Please sign in to comment.