/ test / python / testpipeline / testaudio / testaudiostream.py
testaudiostream.py
 1  """
 2  AudioStream module tests
 3  """
 4  
 5  import unittest
 6  
 7  from unittest.mock import patch
 8  
 9  import soundfile as sf
10  
11  from txtai.pipeline import AudioStream
12  
13  # pylint: disable=C0411
14  from utils import Utils
15  
16  
17  class TestAudioStream(unittest.TestCase):
18      """
19      AudioStream tests.
20      """
21  
22      @patch("sounddevice.play")
23      def testAudioStream(self, play):
24          """
25          Test playing audio
26          """
27  
28          play.return_value = True
29  
30          # Read audio data
31          audio, rate = sf.read(Utils.PATH + "/Make_huge_profits.wav")
32  
33          stream = AudioStream()
34          self.assertIsNotNone(stream([(audio, rate), AudioStream.COMPLETE]))
35  
36          # Wait for completion
37          stream.wait()