From 50473132f8cf65c4f143afa26658a8dcd65dadb0 Mon Sep 17 00:00:00 2001 From: Amjad Natouf Date: Sat, 2 Nov 2024 23:47:12 +0100 Subject: [PATCH] Revert "fix test cases in test_special_features.py" This reverts commit 3f7c4225418ca4a03032ce7fa525501efaca7dbc. --- tests/test_special_features.py | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/tests/test_special_features.py b/tests/test_special_features.py index 361683be..9dd2574e 100644 --- a/tests/test_special_features.py +++ b/tests/test_special_features.py @@ -10,39 +10,16 @@ class TestSpecialFeatures(unittest.TestCase): def setUp(self): - # Define paths to audio files self.AUDIO_FILE_EN = os.path.join(os.path.dirname(os.path.realpath(__file__)), "english.wav") - self.AUDIO_FILE_EN_MP3 = os.path.join(os.path.dirname(os.path.realpath(__file__)), "english.mp3") self.addTypeEqualityFunc(str, self.assertSameWords) @unittest.skipIf(sys.platform.startswith("win"), "skip on Windows") def test_sphinx_keywords(self): r = sr.Recognizer() with sr.AudioFile(self.AUDIO_FILE_EN) as source: audio = r.record(source) - self.assertNotEqual(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=[("one", 0.01), ("two", 0.02), ("three", 0.03)]), "three two one") - self.assertNotEqual(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=[("wan", 0.01), ("too", 0.02), ("tree", 0.03)]), "tree too wan") - self.assertNotEqual(r.recognize_sphinx(audio, keyword_entries=[("wan", 0), ("un", 0.95), ("to", 1.0), ("tee", 1.0)]), "tee to un") - # self.assertEqual(r.recognize_sphinx(audio, keyword_entries=[("un", 0.01), ("to", 0.02), ("tee", 0.03)]), "tee to un") - - # Added test for MP3 - # Test that attempting to recognize speech from an incompatible audio file raises a ValueError.""" - def test_incompatible_audio_file_error(self): - - # Create a Recognizer instance - r = sr.Recognizer() - # Verify that a ValueError is raised when an incompatible audio file is used - with self.assertRaises(ValueError) as context: - # Load the audio file for recognition - # Attempt to record audio from the MP3 file - with sr.AudioFile(self.AUDIO_FILE_EN_MP3) as source:r.record(source) - - # Check that the raised ValueError contains the expected message - self.assertEqual( - str(context.exception), - "Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format" - ) + 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())