Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,14 +10,16 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
| 10 |
model.to(device)
|
| 11 |
|
| 12 |
def transcribe(audio):
|
|
|
|
| 13 |
try:
|
| 14 |
if audio is None:
|
| 15 |
-
return "No audio provided"
|
| 16 |
|
| 17 |
sr, data = audio
|
| 18 |
print(f"Sample rate: {sr}, Audio shape: {len(data)}")
|
| 19 |
|
| 20 |
-
waveform = torch.tensor(data).unsqueeze(0)
|
|
|
|
| 21 |
|
| 22 |
if sr != 16000:
|
| 23 |
resampler = torchaudio.transforms.Resample(orig_freq=sr, new_freq=16000)
|
|
|
|
| 10 |
model.to(device)
|
| 11 |
|
| 12 |
def transcribe(audio):
|
| 13 |
+
def transcribe(audio):
|
| 14 |
try:
|
| 15 |
if audio is None:
|
| 16 |
+
return "No audio provided."
|
| 17 |
|
| 18 |
sr, data = audio
|
| 19 |
print(f"Sample rate: {sr}, Audio shape: {len(data)}")
|
| 20 |
|
| 21 |
+
waveform = torch.tensor(data, dtype=torch.float32).unsqueeze(0)
|
| 22 |
+
waveform = waveform / 32768.0 # normalize 16-bit PCM
|
| 23 |
|
| 24 |
if sr != 16000:
|
| 25 |
resampler = torchaudio.transforms.Resample(orig_freq=sr, new_freq=16000)
|