-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_speech_processor.py
More file actions
31 lines (24 loc) · 993 Bytes
/
Copy pathtest_speech_processor.py
File metadata and controls
31 lines (24 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import unittest
from io import BytesIO
from fastapi import UploadFile
from main import SpeechProcessor
class TestSpeechProcessor(unittest.TestCase):
def setUp(self):
self.speech_processor = SpeechProcessor()
def test_speech_to_text(self):
# Use a real (valid) dummy wav file
with open("test.wav", "rb") as f:
audio_content = BytesIO(f.read())
audio_file = UploadFile(filename="test.wav", file=audio_content)
result = self.speech_processor.speech_to_text(audio_file)
self.assertIsNotNone(result)
self.assertIsInstance(result, str)
def test_text_to_speech(self):
text = "Hello world!"
result = self.speech_processor.text_to_speech(text)
self.assertIsNone(result) # Text-to-speech returns None
def test_text_to_speech_empty_text(self):
with self.assertRaises(ValueError):
self.speech_processor.text_to_speech("")
if __name__ == '__main__':
unittest.main()