Esempio n. 1
0
 def test_ndarray_s16p_align_8(self):
     frame = AudioFrame(format="s16p",
                        layout="stereo",
                        samples=159,
                        align=8)
     array = frame.to_ndarray()
     self.assertEqual(array.dtype, "i2")
     self.assertEqual(array.shape, (2, 159))
Esempio n. 2
0
 def test_ndarray_s16p_align_8(self):
     frame = AudioFrame(format='s16p',
                        layout='stereo',
                        samples=159,
                        align=8)
     array = frame.to_ndarray()
     self.assertEqual(array.dtype, '<i2')
     self.assertEqual(array.shape, (2, 159))
Esempio n. 3
0
    def process_audio(frame: av.AudioFrame) -> av.AudioFrame:
        raw_samples = frame.to_ndarray()
        sound = pydub.AudioSegment(
            data=raw_samples.tobytes(),
            sample_width=frame.format.bytes,
            frame_rate=frame.sample_rate,
            channels=len(frame.layout.channels),
        )

        sound = sound.apply_gain(gain)

        # Ref: https://github.com/jiaaro/pydub/blob/master/API.markdown#audiosegmentget_array_of_samples  # noqa
        channel_sounds = sound.split_to_mono()
        channel_samples = [s.get_array_of_samples() for s in channel_sounds]
        new_samples: np.ndarray = np.array(channel_samples).T
        new_samples = new_samples.reshape(raw_samples.shape)

        new_frame = av.AudioFrame.from_ndarray(new_samples, layout=frame.layout.name)
        new_frame.sample_rate = frame.sample_rate
        return new_frame
Esempio n. 4
0
 def test_basic_to_ndarray(self):
     frame = AudioFrame(format="s16p", layout="stereo", samples=160)
     array = frame.to_ndarray()
     self.assertEqual(array.dtype, "i2")
     self.assertEqual(array.shape, (2, 160))
Esempio n. 5
0
 def test_basic_to_ndarray(self):
     frame = AudioFrame(format='s16p', layout='stereo', samples=160)
     array = frame.to_ndarray()
     self.assertEqual(array.dtype, '<i2')
     self.assertEqual(array.shape, (2, 160))
Esempio n. 6
0
 def test_basic_to_ndarray(self):
     frame = AudioFrame(format='s16p', layout='stereo', samples=160)
     array = frame.to_ndarray()
     self.assertEqual(array.dtype, '<i2')
     self.assertEqual(array.shape, (2, 160))
Esempio n. 7
0
 def test_ndarray_s16p_align_8(self):
     frame = AudioFrame(format='s16p', layout='stereo', samples=159, align=8)
     array = frame.to_ndarray()
     self.assertEqual(array.dtype, '<i2')
     self.assertEqual(array.shape, (2, 159))