Skip to content

Commit

Permalink
use ffmpeg in priority if available, then fall back to torchaudio
Browse files Browse the repository at this point in the history
  • Loading branch information
adefossez committed May 11, 2021
1 parent dfa3177 commit 694ca67
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions demucs/separate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,26 @@
def load_track(track, device, audio_channels, samplerate):
errors = {}
wav = None

try:
wav, sr = ta.load(str(track))
except RuntimeError as err:
errors['torchaudio'] = err.args[0]
wav = AudioFile(track).read(
streams=0,
samplerate=samplerate,
channels=audio_channels).to(device)
except FileNotFoundError:
errors['ffmpeg'] = 'Ffmpeg is not installed.'
except subprocess.CalledProcessError:
errors['ffmpeg'] = 'FFmpeg could not read the file.'

if wav is None:
try:
wav = AudioFile(track).read(
streams=0,
samplerate=samplerate,
channels=audio_channels).to(device)
except FileNotFoundError:
errors['ffmpeg'] = 'Ffmpeg is not installed.'
except subprocess.CalledProcessError:
errors['ffmpeg'] = 'FFmpeg could not read the file.'
else:
wav = convert_audio_channels(wav, audio_channels)
wav = wav.to(device)
wav = julius.resample_frac(wav, sr, samplerate)
wav, sr = ta.load(str(track))
except RuntimeError as err:
errors['torchaudio'] = err.args[0]
else:
wav = convert_audio_channels(wav, audio_channels)
wav = wav.to(device)
wav = julius.resample_frac(wav, sr, samplerate)

if wav is None:
print(f"Could not load file {track}. "
Expand Down

0 comments on commit 694ca67

Please sign in to comment.