Skip to content

Commit 3cc29a6

Browse files
committed
Fix portable temporary named files on Python 2 and bump version
1 parent c6a583b commit 3cc29a6

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

speech_recognition/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import uuid
2222

2323
__author__ = "Anthony Zhang (Uberi)"
24-
__version__ = "3.6.4"
24+
__version__ = "3.6.5"
2525
__license__ = "BSD"
2626

2727
try: # attempt to use the Python 2 modules
@@ -1105,7 +1105,7 @@ def __enter__(self):
11051105
# create the temporary file and open it
11061106
import tempfile
11071107
file_descriptor, file_path = tempfile.mkstemp()
1108-
self._file = open(file_descriptor, self.mode)
1108+
self._file = os.fdopen(file_descriptor, self.mode)
11091109

11101110
# the name property is a public field
11111111
self.name = file_path

tests/test_special_features.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import os
5+
import unittest
6+
7+
import speech_recognition as sr
8+
9+
10+
class TestSpecialFeatures(unittest.TestCase):
11+
def setUp(self):
12+
self.AUDIO_FILE_EN = os.path.join(os.path.dirname(os.path.realpath(__file__)), "english.wav")
13+
14+
def test_sphinx_keywords(self):
15+
r = sr.Recognizer()
16+
with sr.AudioFile(self.AUDIO_FILE_EN) as source: audio = r.record(source)
17+
self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("one", 1.0), ("two", 1.0), ("three", 1.0)]), "three two two one ")
18+
self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("wan", 0.95), ("too", 1.0), ("tree", 1.0)]), "tree too wan too wan ")
19+
self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("un", 0.95), ("to", 1.0), ("tee", 1.0)]), "tee to un to un un un ")
20+
21+
22+
if __name__ == "__main__":
23+
unittest.main()

0 commit comments

Comments
 (0)