| import torch |
| import torchaudio |
| import soundfile |
| import os |
|
|
| print(f"Torch version: {torch.__version__}") |
| print(f"Torchaudio version: {torchaudio.__version__}") |
| print(f"Soundfile version: {soundfile.__version__}") |
|
|
| print("\nChecking available backends:") |
| try: |
| print(f"List audio backends: {torchaudio.list_audio_backends()}") |
| except: |
| print("torchaudio.list_audio_backends() not available") |
|
|
| try: |
| print(f"Get audio backend: {torchaudio.get_audio_backend()}") |
| except: |
| pass |
|
|
| print("\nTest writing and reading:") |
| test_file = "test_audio.wav" |
| try: |
| |
| waveform = torch.rand(1, 16000) |
| sample_rate = 16000 |
| |
| print(f"Saving {test_file} with backend='soundfile'...") |
| torchaudio.save(test_file, waveform, sample_rate, backend="soundfile") |
| print("Save success.") |
| |
| print(f"Loading {test_file} with backend='soundfile'...") |
| loaded_wav, loaded_sr = torchaudio.load(test_file, backend="soundfile") |
| print(f"Load success. Shape: {loaded_wav.shape}") |
| |
| except Exception as e: |
| import traceback |
| traceback.print_exc() |
| print(f"Test failed: {e}") |
| finally: |
| if os.path.exists(test_file): |
| os.remove(test_file) |
|
|