Skip to content

Commit

Permalink
repalce api in test_audio_backend
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileGoat committed Oct 20, 2022
1 parent 1ca215a commit 160b50e
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions python/paddle/tests/test_audio_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,25 @@ def get_wav_data(dtype: str, num_channels: int, num_frames: int):
def test_backend(self):
base_dir = os.getcwd()
wave_wav_path = os.path.join(base_dir, "wave_test.wav")
paddle.audio.backends.save(wave_wav_path,
paddle.to_tensor(self.waveform),
self.sr,
channels_first=True)
paddle.audio.save(wave_wav_path,
paddle.to_tensor(self.waveform),
self.sr,
channels_first=True)

# test backends(wave)(wave_backend) info
wav_info = paddle.audio.backends.info(wave_wav_path)
wav_info = paddle.audio.info(wave_wav_path)
self.assertTrue(wav_info.sample_rate, self.sr)
self.assertTrue(wav_info.num_channels, self.num_channels)
self.assertTrue(wav_info.bits_per_sample, 16)

with open(wave_wav_path, 'rb') as file_:
wav_info = paddle.audio.backends.info(file_)
wav_info = paddle.audio.info(file_)
self.assertTrue(wav_info.sample_rate, self.sr)
self.assertTrue(wav_info.num_channels, self.num_channels)
self.assertTrue(wav_info.bits_per_sample, 16)

# test backends(wave_backend) load & save
wav_data, sr = paddle.audio.backends.load(wave_wav_path)
wav_data, sr = paddle.audio.load(wave_wav_path)
np.testing.assert_array_almost_equal(wav_data, self.waveform, decimal=4)
with soundfile.SoundFile(wave_wav_path, "r") as file_:
dtype = "float32"
Expand All @@ -74,9 +74,9 @@ def test_backend(self):
np.testing.assert_array_almost_equal(wav_data, waveform)

with open(wave_wav_path, 'rb') as file_:
wav_data, sr = paddle.audio.backends.load(file_,
normalize=False,
num_frames=10000)
wav_data, sr = paddle.audio.load(file_,
normalize=False,
num_frames=10000)
with soundfile.SoundFile(wave_wav_path, "r") as file_:
dtype = "int16"
frames = file_._prepare_read(0, None, -1)
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_backend(self):
paddle.audio.backends.set_backend("soundfile")
current_backend = paddle.audio.backends.get_current_backend()
self.assertTrue(current_backend, "soundfile")
wav_info = paddle.audio.backends.info(wave_wav_path)
wav_info = paddle.audio.info(wave_wav_path)
self.assertTrue(wav_info.sample_rate, self.sr)
self.assertTrue(wav_info.num_channels, self.num_channels)
self.assertTrue(wav_info.bits_per_sample, 16)
Expand All @@ -119,29 +119,29 @@ def test_backend(self):
pass

try:
paddle.audio.backends.save(wave_wav_path,
paddle.to_tensor(self.waveform),
self.sr,
bits_per_sample=24,
channels_first=True)
paddle.audio.save(wave_wav_path,
paddle.to_tensor(self.waveform),
self.sr,
bits_per_sample=24,
channels_first=True)
except ValueError:
pass

try:
paddle.audio.backends.save(
wave_wav_path,
paddle.to_tensor(self.waveform).unsqueeze(0), self.sr)
paddle.audio.save(wave_wav_path,
paddle.to_tensor(self.waveform).unsqueeze(0),
self.sr)
except AssertionError:
pass

fake_data = np.array([0, 1, 2, 3, 4, 6], np.float32)
soundfile.write(wave_wav_path, fake_data, 1, subtype="DOUBLE")
try:
wav_info = paddle.audio.backends.info(wave_wav_path)
wav_info = paddle.audio.info(wave_wav_path)
except NotImplementedError:
pass
try:
wav_data = paddle.audio.backends.load(wave_wav_path)
wav_data = paddle.audio.load(wave_wav_path)
except NotImplementedError:
pass

Expand Down

0 comments on commit 160b50e

Please sign in to comment.