File size: 595 Bytes
a6299ef
405b2f1
 
 
 
 
 
 
 
 
 
a6299ef
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import soundfile as sf
import torch


DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
CUDA_AVAILABLE = DEVICE.type == "cuda"
TORCH_DTYPE = torch.float16 if CUDA_AVAILABLE else torch.float32

print(f"Using device: {DEVICE}")
if CUDA_AVAILABLE:
    print(f"CUDA device: {torch.cuda.get_device_name(DEVICE)}")


def getAudioDuration(filePath: str) -> float:
    try:
        data, samplerate = sf.read(filePath)
        duration = len(data) / samplerate
        return duration
    except Exception as e:
        print(f"Error getting audio duration: {e}")
        return 0.0