@@ -200,6 +200,68 @@ def assert_sphere(self, sample_rate, num_channels, duration):
200200
201201 self .assertEqual (found , expected )
202202
203+ def assert_amb (self , dtype , sample_rate , num_channels , duration ):
204+ """`sox_io_backend.save` can save amb format.
205+
206+ This test takes the same strategy as mp3 to compare the result
207+ """
208+ src_path = self .get_temp_path ('1.reference.wav' )
209+ amb_path = self .get_temp_path ('2.1.torchaudio.amb' )
210+ wav_path = self .get_temp_path ('2.2.torchaudio.wav' )
211+ amb_path_sox = self .get_temp_path ('3.1.sox.amb' )
212+ wav_path_sox = self .get_temp_path ('3.2.sox.wav' )
213+
214+ # 1. Generate original wav
215+ data = get_wav_data (dtype , num_channels , normalize = False , num_frames = duration * sample_rate )
216+ save_wav (src_path , data , sample_rate )
217+ # 2.1. Convert the original wav to amb with torchaudio
218+ sox_io_backend .save (amb_path , load_wav (src_path , normalize = False )[0 ], sample_rate )
219+ # 2.2. Convert the amb to wav with Sox
220+ sox_utils .convert_audio_file (amb_path , wav_path )
221+ # 2.3. Load
222+ found = load_wav (wav_path )[0 ]
223+
224+ # 3.1. Convert the original wav to amb with SoX
225+ sox_utils .convert_audio_file (src_path , amb_path_sox )
226+ # 3.2. Convert the amb to wav with Sox
227+ sox_utils .convert_audio_file (amb_path_sox , wav_path_sox )
228+ # 3.3. Load
229+ expected = load_wav (wav_path_sox )[0 ]
230+
231+ self .assertEqual (found , expected )
232+
233+ def assert_amr_nb (self , duration ):
234+ """`sox_io_backend.save` can save amr_nb format.
235+
236+ This test takes the same strategy as mp3 to compare the result
237+ """
238+ sample_rate = 8000
239+ num_channels = 1
240+ src_path = self .get_temp_path ('1.reference.wav' )
241+ amr_path = self .get_temp_path ('2.1.torchaudio.amr-nb' )
242+ wav_path = self .get_temp_path ('2.2.torchaudio.wav' )
243+ amr_path_sox = self .get_temp_path ('3.1.sox.amr-nb' )
244+ wav_path_sox = self .get_temp_path ('3.2.sox.wav' )
245+
246+ # 1. Generate original wav
247+ data = get_wav_data ('int16' , num_channels , normalize = False , num_frames = duration * sample_rate )
248+ save_wav (src_path , data , sample_rate )
249+ # 2.1. Convert the original wav to amr_nb with torchaudio
250+ sox_io_backend .save (amr_path , load_wav (src_path , normalize = False )[0 ], sample_rate )
251+ # 2.2. Convert the amr_nb to wav with Sox
252+ sox_utils .convert_audio_file (amr_path , wav_path )
253+ # 2.3. Load
254+ found = load_wav (wav_path )[0 ]
255+
256+ # 3.1. Convert the original wav to amr_nb with SoX
257+ sox_utils .convert_audio_file (src_path , amr_path_sox )
258+ # 3.2. Convert the amr_nb to wav with Sox
259+ sox_utils .convert_audio_file (amr_path_sox , wav_path_sox )
260+ # 3.3. Load
261+ expected = load_wav (wav_path_sox )[0 ]
262+
263+ self .assertEqual (found , expected )
264+
203265
204266@skipIfNoExec ('sox' )
205267@skipIfNoExtension
@@ -302,6 +364,19 @@ def test_sphere(self, sample_rate, num_channels):
302364 """`sox_io_backend.save` can save sph format."""
303365 self .assert_sphere (sample_rate , num_channels , duration = 1 )
304366
367+ @parameterized .expand (list (itertools .product (
368+ ['float32' , 'int32' , 'int16' , 'uint8' ],
369+ [8000 , 16000 ],
370+ [1 , 2 ],
371+ )), name_func = name_func )
372+ def test_amb (self , dtype , sample_rate , num_channels ):
373+ """`sox_io_backend.save` can save amb format."""
374+ self .assert_amb (dtype , sample_rate , num_channels , duration = 1 )
375+
376+ def test_amr_nb (self ):
377+ """`sox_io_backend.save` can save amr-nb format."""
378+ self .assert_amr_nb (duration = 1 )
379+
305380
306381@skipIfNoExec ('sox' )
307382@skipIfNoExtension
0 commit comments