Spaces:
Sleeping
Sleeping
colab-user commited on
Commit ·
298639e
1
Parent(s): ce62dd2
add denoise & audio enhancement
Browse files
app/services/audio_processor.py
CHANGED
|
@@ -24,10 +24,9 @@ class AudioProcessingError(Exception):
|
|
| 24 |
|
| 25 |
|
| 26 |
class AudioProcessor:
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
"""
|
| 31 |
|
| 32 |
@classmethod
|
| 33 |
def validate_file(cls, filename: str, file_size: int) -> None:
|
|
@@ -136,6 +135,31 @@ class AudioProcessor:
|
|
| 136 |
.run(quiet=True, capture_stderr=True)
|
| 137 |
)
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
@classmethod
|
| 140 |
async def cleanup_files(cls, *paths: Path) -> None:
|
| 141 |
"""Remove temporary files."""
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
class AudioProcessor:
|
| 27 |
+
ALLOWED_EXTENSIONS = settings.allowed_extensions
|
| 28 |
+
TARGET_SAMPLE_RATE = settings.sample_rate
|
| 29 |
+
TARGET_CHANNELS = settings.channels
|
|
|
|
| 30 |
|
| 31 |
@classmethod
|
| 32 |
def validate_file(cls, filename: str, file_size: int) -> None:
|
|
|
|
| 135 |
.run(quiet=True, capture_stderr=True)
|
| 136 |
)
|
| 137 |
|
| 138 |
+
|
| 139 |
+
@classmethod
|
| 140 |
+
async def get_audio_duration(cls, filepath: Path) -> float:
|
| 141 |
+
"""
|
| 142 |
+
Get audio file duration in seconds.
|
| 143 |
+
|
| 144 |
+
Args:
|
| 145 |
+
filepath: Path to audio file
|
| 146 |
+
|
| 147 |
+
Returns:
|
| 148 |
+
Duration in seconds
|
| 149 |
+
"""
|
| 150 |
+
try:
|
| 151 |
+
loop = asyncio.get_event_loop()
|
| 152 |
+
probe = await loop.run_in_executor(
|
| 153 |
+
None,
|
| 154 |
+
lambda: ffmpeg.probe(str(filepath))
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
duration = float(probe['format'].get('duration', 0))
|
| 158 |
+
return duration
|
| 159 |
+
|
| 160 |
+
except ffmpeg.Error as e:
|
| 161 |
+
logger.warning(f"Could not probe audio duration: {e}")
|
| 162 |
+
return 0.0
|
| 163 |
@classmethod
|
| 164 |
async def cleanup_files(cls, *paths: Path) -> None:
|
| 165 |
"""Remove temporary files."""
|