Spaces:
Paused
Paused
rick
commited on
add audio isolation feature
Browse files- core/audio_isolation.py +33 -0
core/audio_isolation.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
#coding: utf-8
|
| 3 |
+
|
| 4 |
+
# FEATURE:
|
| 5 |
+
# Removes background noise from audio
|
| 6 |
+
# REQUIREMENT:
|
| 7 |
+
# That use the ELEVENLABS API
|
| 8 |
+
|
| 9 |
+
from typing import Optional
|
| 10 |
+
from typing import Union
|
| 11 |
+
from typing import List
|
| 12 |
+
from typing import Dict
|
| 13 |
+
from typing import Any
|
| 14 |
+
import requests
|
| 15 |
+
import json
|
| 16 |
+
import os
|
| 17 |
+
import tempfile
|
| 18 |
+
|
| 19 |
+
from dotenv import load_dotenv
|
| 20 |
+
from elevenlabs import ElevenLabs
|
| 21 |
+
|
| 22 |
+
def isolate_audio(fichier_audio: str, api_key: str):
|
| 23 |
+
client = ElevenLabs(api_key=api_key)
|
| 24 |
+
|
| 25 |
+
with open(fichier_audio, 'rb') as audio_file:
|
| 26 |
+
response = client.audio_isolation.audio_isolation(audio=audio_file)
|
| 27 |
+
|
| 28 |
+
if response.status_code == 200:
|
| 29 |
+
with open("audio_isole.mp3", "wb") as output_file:
|
| 30 |
+
output_file.write(response.content)
|
| 31 |
+
print("L'audio a été isolé avec succès et enregistré sous 'audio_isole.mp3'.")
|
| 32 |
+
else:
|
| 33 |
+
print(f"Erreur lors de l'isolement de l'audio: {response.status_code}, {response.text}")
|