Beispiel #1
0
 def setUp(self):
     self.id = 0
     self.final_hypothesis = [(1.0, "Hello World!")]
     self.model = "en-GB"
     self.chunk = b"chunk"
     self.frame_rate = 44100
     self.socket = SocketSpy()
     self.saver = RemoteSaver(self.socket, self.model)
Beispiel #2
0
 def setUp(self):
     self.id = 0
     self.final_hypothesis = [(1.0, "Hello World!")]
     self.model = "en-GB"
     self.chunk = b"chunk"
     self.frame_rate = 44100
     self.socket = SocketSpy()
     self.saver = RemoteSaver(self.socket, self.model)
Beispiel #3
0
class RemoteSaverTest(unittest.TestCase):
    def setUp(self):
        self.id = 0
        self.chunk_id = 0
        self.part = 0
        self.final_hypothesis = [(1.0, "Hello World!")]
        self.model = "en-GB"
        self.chunk = b"chunk"
        self.frame_rate = 44100
        self.socket = SocketSpy()
        self.saver = RemoteSaver(self.socket, self.model)

    def test_saver_sends_all_information(self):
        self.saver.new_recognition(createUniqueID(self.id), self.frame_rate)
        self.saver.add_pcm(self.chunk)
        self.saver.add_pcm(self.chunk)
        self.saver.final_hypothesis(self.chunk_id, self.final_hypothesis)

        message = parseSaverMessage(self.socket.sent_message)
        self.assertEquals(self.id, uniqId2Int(message.id))
        self.assertEquals(self.part, message.part)
        self.assertEquals(self.model, message.model)
        self.assertEquals(self.chunk * 2, message.body)
        self.assertEquals(self.frame_rate, message.frame_rate)
        self.assertEquals([{
            "confidence": self.final_hypothesis[0][0],
            "transcript": self.final_hypothesis[0][1]
        }], alternatives2List(message.alternatives))

    def test_saver_sends_all_parts(self):
        self.saver.new_recognition(createUniqueID(self.id), self.frame_rate)
        self.saver.add_pcm(self.chunk)
        self.saver.final_hypothesis(self.chunk_id, self.final_hypothesis)
        self.saver.add_pcm(self.chunk)
        self.saver.final_hypothesis(self.chunk_id, self.final_hypothesis)

        message = parseSaverMessage(self.socket.sent_messages[0])
        self.assertEquals(0, message.part)

        message = parseSaverMessage(self.socket.sent_messages[1])
        self.assertEquals(1, message.part)

    def test_saver_resets_after_final_hypothesis(self):
        self.saver.new_recognition(createUniqueID(self.id))
        self.saver.add_pcm(self.chunk)
        self.saver.final_hypothesis(self.chunk_id, self.final_hypothesis)
        self.saver.new_recognition(createUniqueID(self.id + 1))
        self.saver.add_pcm(self.chunk)
        self.saver.final_hypothesis(self.chunk_id, self.final_hypothesis)

        message = parseSaverMessage(self.socket.sent_message)
        self.assertEquals(self.id + 1, uniqId2Int(message.id))
        self.assertEquals(self.chunk, message.body)

    def test_saver_doesnt_save_anything_when_wav_is_empty(self):
        self.saver.new_recognition(createUniqueID(self.id))
        self.saver.final_hypothesis(self.chunk_id, self.final_hypothesis)

        self.assertEquals(self.socket.sent_message, None)
Beispiel #4
0
class RemoteSaverTest(unittest.TestCase):

    def setUp(self):
        self.id = 0
        self.final_hypothesis = [(1.0, "Hello World!")]
        self.model = "en-GB"
        self.chunk = b"chunk"
        self.frame_rate = 44100
        self.socket = SocketSpy()
        self.saver = RemoteSaver(self.socket, self.model)

    def test_saver_sends_all_information(self):
        self.saver.new_recognition(createUniqueID(self.id), self.frame_rate)
        self.saver.add_pcm(self.chunk)
        self.saver.add_pcm(self.chunk)
        self.saver.final_hypothesis(self.final_hypothesis)

        message = parseSaverMessage(self.socket.sent_message)
        self.assertEquals(self.model, message.model)
        self.assertEquals(self.chunk * 2, message.body)
        self.assertEquals(self.frame_rate, message.frame_rate)
        self.assertEquals(self.id, uniqId2Int(message.id))
        self.assertEquals([{"confidence": self.final_hypothesis[0][0], "transcript": self.final_hypothesis[0][1]}], alternatives2List(message.alternatives))

    def test_saver_resets_after_final_hypothesis(self):
        self.saver.new_recognition(createUniqueID(self.id))
        self.saver.add_pcm(self.chunk)
        self.saver.final_hypothesis(self.final_hypothesis)
        self.saver.new_recognition(createUniqueID(self.id + 1))
        self.saver.add_pcm(self.chunk)
        self.saver.final_hypothesis(self.final_hypothesis)

        message = parseSaverMessage(self.socket.sent_message)
        self.assertEquals(self.id + 1, uniqId2Int(message.id))
        self.assertEquals(self.chunk, message.body)