vinthony commited on
Commit
defda6e
1 Parent(s): a25e496

Update src/generate_batch.py

Browse files
Files changed (1) hide show
  1. src/generate_batch.py +11 -3
src/generate_batch.py CHANGED
@@ -6,6 +6,14 @@ import scipy.io as scio
6
  import src.utils.audio as audio
7
  import subprocess, platform
8
 
 
 
 
 
 
 
 
 
9
  def crop_pad_audio(wav, audio_length):
10
  if len(wav) > audio_length:
11
  wav = wav[:audio_length]
@@ -64,9 +72,9 @@ def get_data(first_coeff_path, audio_path, device):
64
  ref_coeff = source_semantics_dict['coeff_3dmm'][:1,:70] #1 70
65
 
66
  if '.mp3' in audio_path:
67
- new_audio = audio_path.replace('.mp3', '.wav')
68
- command = 'ffmpeg -i '+ audio_path + ' ' + new_audio
69
- subprocess.call(command, shell=platform.system() != 'Windows')
70
  else:
71
  new_audio = audio_path
72
 
 
6
  import src.utils.audio as audio
7
  import subprocess, platform
8
 
9
+ from pydub import AudioSegment
10
+
11
+ def mp3_to_wav(mp3_filename,wav_filename,frame_rate):
12
+ mp3_file = AudioSegment.from_mp3(file=mp3_filename)
13
+ mp3_file.set_frame_rate(frame_rate).export(wav_filename,format="wav")
14
+
15
+
16
+
17
  def crop_pad_audio(wav, audio_length):
18
  if len(wav) > audio_length:
19
  wav = wav[:audio_length]
 
72
  ref_coeff = source_semantics_dict['coeff_3dmm'][:1,:70] #1 70
73
 
74
  if '.mp3' in audio_path:
75
+ print(audio_path)
76
+ mp3_to_wav(audio_path, audio_path.replace('.mp3','.wav'), 16000)
77
+ new_audio = audio_path.replace('.mp3','.wav')
78
  else:
79
  new_audio = audio_path
80