File: backend_utils.py

package info (click to toggle)
pytorch-audio 0.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,512 kB
  • sloc: python: 15,606; cpp: 1,352; sh: 257; makefile: 21
file content (23 lines) | stat: -rw-r--r-- 656 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import unittest

import torchaudio


def set_audio_backend(backend):
    """Allow additional backend value, 'default'"""
    backends = torchaudio.list_audio_backends()
    if backend == 'soundfile-new':
        be = 'soundfile'
        torchaudio.USE_SOUNDFILE_LEGACY_INTERFACE = False
    elif backend == 'default':
        if 'sox_io' in backends:
            be = 'sox_io'
        elif 'soundfile' in backends:
            be = 'soundfile'
            torchaudio.USE_SOUNDFILE_LEGACY_INTERFACE = True
        else:
            raise unittest.SkipTest('No default backend available')
    else:
        be = backend

    torchaudio.set_audio_backend(be)