Ejemplo n.º 1
0
 def test_downmixing_playable(self):
     """
     Test that downmixing results in playable audio.
     """
     seg = audiosegment.from_file("stereo_furelise.wav")
     mono = seg.resample(channels=1)
     self.assertTrue(common.is_playable(mono))
Ejemplo n.º 2
0
 def test_upmix_then_downmix_stereo(self):
     """
     """
     seg = audiosegment.from_file("stereo_furelise.wav")
     remixed = seg.resample(channels=8)
     unmixed = remixed.resample(channels=2)
     self._check_underlying_data(seg, unmixed)
     self.assertTrue(common.is_playable(unmixed))
Ejemplo n.º 3
0
 def test_upmix_then_downmix_mono(self):
     """
     Test that upmixing and then downmixing does not change the audio.
     """
     seg = audiosegment.from_file("furelise.wav")
     remixed = seg.resample(channels=8)
     unmixed = remixed.resample(channels=1)
     self._check_underlying_data(seg, unmixed)
     self.assertTrue(common.is_playable(unmixed))
Ejemplo n.º 4
0
    def test_create_file_from_four_monos(self):
        """
        """
        mono = audiosegment.from_file("furelise.wav")
        multi = self._test_create_file_from_n_segments(mono, 4)
        self.assertTrue(common.is_playable(multi))

        # Now test that all channels are identical
        arr = multi.to_numpy_array()
        self.assertTrue(np.allclose(arr[:, 0], arr[:, 1]))
        self.assertTrue(np.allclose(arr[:, 1], arr[:, 2]))
        self.assertTrue(np.allclose(arr[:, 2], arr[:, 3]))
Ejemplo n.º 5
0
    def test_create_file_from_two_monos(self):
        """
        Tests that we can create a playable wav file from copying a single
        mono wave file into stereo.
        """
        mono = audiosegment.from_file("furelise.wav")
        multi = self._test_create_file_from_n_segments(mono, 2)
        self.assertTrue(common.is_playable(multi))

        # Now test that both channels are identical
        arr = multi.to_numpy_array()
        self.assertTrue(np.allclose(arr[:, 0], arr[:, 1]))
Ejemplo n.º 6
0
    def test_stereo_to_and_from_numpy_array(self):
        """
        Tests that we can convert a stereo file to a numpy array and then back again
        without any changes.
        """
        before = audiosegment.from_file("stereo_furelise.wav")
        arr = before.to_numpy_array()
        after = audiosegment.from_numpy_array(arr, before.frame_rate)

        self.assertEqual(before.sample_width, after.sample_width)
        self.assertEqual(before.duration_seconds, after.duration_seconds)
        self.assertEqual(before.channels, after.channels)
        self.assertSequenceEqual(before.raw_data, after.raw_data)
        self.assertTrue(common.is_playable(after))
Ejemplo n.º 7
0
 def test_stereo_from_numpy_array(self):
     """
     Test that we can create and play a stereo numpy array.
     """
     duration_s = 2.0
     fs = 16000
     tone_one = 100 * common.synthesize_pure_tone_array(
         duration_s, fs, ft=3200)
     tone_two = 100 * common.synthesize_pure_tone_array(
         duration_s, fs, ft=2800)
     stereo_arr = np.array([tone_one, tone_two], dtype=np.int16).reshape(
         (-1, 2))
     stereo_seg = audiosegment.from_numpy_array(stereo_arr, fs)
     self.assertTrue(common.is_playable(stereo_seg))
Ejemplo n.º 8
0
    def test_mono_to_and_from(self):
        """
        Test that a mono file converts to a numpy array and back again without any change.
        """
        seg = audiosegment.from_file("furelise.wav")

        for width in (1, 2, 4):
            with self.subTest(width):
                seg = seg.resample(sample_width=width)
                arr = seg.to_numpy_array()
                seg = audiosegment.from_numpy_array(arr, seg.frame_rate)
                nsamples = int(round(seg.frame_rate * seg.duration_seconds))

                self.assertEqual(seg.sample_width,
                                 self._look_up_sample_width(arr.dtype))
                self.assertEqual(arr.shape, (nsamples, ))
                self._check_underlying_data(seg, arr)
                self.assertTrue(common.is_playable(seg))
Ejemplo n.º 9
0
    def test_mono_from_numpy_array(self):
        """
        Test that creating a mono audio segment from a numpy array creates
        what we expected.
        """
        duration_s = 3.5
        fs = 32000
        ftone = 4000
        arr = np.int16(
            100 * common.synthesize_pure_tone_array(duration_s, fs, ftone))
        seg = audiosegment.from_numpy_array(arr, fs)

        sample_width = self._look_up_sample_width(arr.dtype)
        nsamples = int(round(seg.frame_rate * seg.duration_seconds))

        self.assertEqual(seg.sample_width, sample_width)
        self.assertEqual(nsamples, len(arr))
        self.assertEqual(arr.shape, (nsamples, ))
        self._check_underlying_data(seg, arr)
        self.assertTrue(common.is_playable(seg))