File size: 1,187 Bytes
6319e2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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:
    # Generate dummy audio
    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)