Spaces:
Running
on
Zero
Running
on
Zero
use torchaudio
Browse files
app.py
CHANGED
@@ -13,6 +13,8 @@ from datasets import Dataset, DatasetDict, concatenate_datasets, Audio, load_dat
|
|
13 |
from transformers import pipeline
|
14 |
from huggingface_hub import HfApi, login
|
15 |
from resemble_enhance.enhancer.inference import denoise, enhance
|
|
|
|
|
16 |
|
17 |
# Configure logging
|
18 |
logging.basicConfig(
|
@@ -69,17 +71,7 @@ def save_dataset(dataset: Dataset, dataset_name: str) -> None:
|
|
69 |
logger.info(f"Pushed updated dataset to '{dataset_name}' ({len(dataset)} records).")
|
70 |
|
71 |
|
72 |
-
|
73 |
-
"""
|
74 |
-
Load audio file, convert to mono and target sampling rate.
|
75 |
-
Returns audio array and sampling rate.
|
76 |
-
"""
|
77 |
-
try:
|
78 |
-
data, sr = librosa.load(filepath, sr=target_sr, mono=True)
|
79 |
-
return data, sr
|
80 |
-
except Exception as exc:
|
81 |
-
logger.error(f"Failed to process audio file '{filepath}': {exc}")
|
82 |
-
raise
|
83 |
|
84 |
|
85 |
class Transcriber:
|
@@ -106,11 +98,11 @@ def transcribe_and_update(audio_filepath: str, history: str, apply_enhance: bool
|
|
106 |
|
107 |
try:
|
108 |
# Load and preprocess
|
109 |
-
audio_data, sr =
|
110 |
-
|
111 |
# Always denoise
|
112 |
try:
|
113 |
device = "cuda"
|
|
|
114 |
denoised_data, sr = denoise(audio_data, sr, device)
|
115 |
logger.info("Audio denoised successfully.")
|
116 |
except Exception as e:
|
|
|
13 |
from transformers import pipeline
|
14 |
from huggingface_hub import HfApi, login
|
15 |
from resemble_enhance.enhancer.inference import denoise, enhance
|
16 |
+
import torchaudio
|
17 |
+
|
18 |
|
19 |
# Configure logging
|
20 |
logging.basicConfig(
|
|
|
71 |
logger.info(f"Pushed updated dataset to '{dataset_name}' ({len(dataset)} records).")
|
72 |
|
73 |
|
74 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
|
77 |
class Transcriber:
|
|
|
98 |
|
99 |
try:
|
100 |
# Load and preprocess
|
101 |
+
audio_data, sr = dwav, sr = torchaudio.load(audio_filepath)
|
|
|
102 |
# Always denoise
|
103 |
try:
|
104 |
device = "cuda"
|
105 |
+
audio_data = audio_data.mean(dim=0)
|
106 |
denoised_data, sr = denoise(audio_data, sr, device)
|
107 |
logger.info("Audio denoised successfully.")
|
108 |
except Exception as e:
|