Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -62,20 +62,43 @@ css = """
|
|
62 |
.tips {background: #e7f5ff; padding: 15px; border-radius: 5px; margin-top: 20px;}
|
63 |
"""
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
def process_audio(
|
66 |
audio_path: str,
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
) -> Tuple[str, Dict]:
|
71 |
"""
|
72 |
Ses dosyasını işleyip transkripsiyon yapar.
|
73 |
|
74 |
Args:
|
75 |
audio_path: Ses dosyasının yolu
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
|
80 |
Returns:
|
81 |
Tuple[str, Dict]: (Transkripsiyon metni, JSON sonuç)
|
@@ -90,12 +113,12 @@ def process_audio(
|
|
90 |
audio = AudioSegment.from_file(audio_path)
|
91 |
|
92 |
# Ses iyileştirme
|
93 |
-
if
|
94 |
audio = enhance_audio(audio)
|
95 |
audio.export(wav_path, format="wav")
|
96 |
|
97 |
# Konuşmacı ayrımı
|
98 |
-
if
|
99 |
diarization = diarize_speakers(wav_path)
|
100 |
else:
|
101 |
diarization = None
|
@@ -104,15 +127,15 @@ def process_audio(
|
|
104 |
result = transcribe_audio(wav_path, diarization)
|
105 |
|
106 |
# Anonimleştirme
|
107 |
-
if
|
108 |
result = anonymize_personal_info(result)
|
109 |
|
110 |
# JSON çıktısını hazırla
|
111 |
json_result = {
|
112 |
"transcript": result["text"],
|
113 |
"diarization": diarization,
|
114 |
-
"enhanced_audio": wav_path if
|
115 |
-
"anonymized":
|
116 |
}
|
117 |
|
118 |
return result["text"], json_result
|
|
|
62 |
.tips {background: #e7f5ff; padding: 15px; border-radius: 5px; margin-top: 20px;}
|
63 |
"""
|
64 |
|
65 |
+
def enhance_audio(audio: AudioSegment) -> AudioSegment:
|
66 |
+
"""Ses kalitesini iyileştir"""
|
67 |
+
# Basit ses iyileştirme: normalize et
|
68 |
+
return audio.normalize()
|
69 |
+
|
70 |
+
def diarize_speakers(audio_path: str) -> list:
|
71 |
+
"""Konuşmacıları ayır"""
|
72 |
+
# TODO: Gerçek diarization implementasyonu
|
73 |
+
return []
|
74 |
+
|
75 |
+
def transcribe_audio(audio_path: str, diarization: list = None) -> Dict:
|
76 |
+
"""Ses dosyasını metne çevir"""
|
77 |
+
# TODO: Gerçek transkripsiyon implementasyonu
|
78 |
+
return {
|
79 |
+
"text": "Örnek transkripsiyon metni",
|
80 |
+
"segments": []
|
81 |
+
}
|
82 |
+
|
83 |
+
def anonymize_personal_info(result: Dict) -> Dict:
|
84 |
+
"""Kişisel bilgileri anonimleştir"""
|
85 |
+
# TODO: Gerçek anonimleştirme implementasyonu
|
86 |
+
return result
|
87 |
+
|
88 |
def process_audio(
|
89 |
audio_path: str,
|
90 |
+
diarize: bool = True,
|
91 |
+
enhance: bool = True,
|
92 |
+
anonymize: bool = True
|
93 |
) -> Tuple[str, Dict]:
|
94 |
"""
|
95 |
Ses dosyasını işleyip transkripsiyon yapar.
|
96 |
|
97 |
Args:
|
98 |
audio_path: Ses dosyasının yolu
|
99 |
+
diarize: Konuşmacı ayrımı yapılsın mı?
|
100 |
+
enhance: Ses iyileştirme yapılsın mı?
|
101 |
+
anonymize: Kişisel veriler anonimleştirilsin mi?
|
102 |
|
103 |
Returns:
|
104 |
Tuple[str, Dict]: (Transkripsiyon metni, JSON sonuç)
|
|
|
113 |
audio = AudioSegment.from_file(audio_path)
|
114 |
|
115 |
# Ses iyileştirme
|
116 |
+
if enhance:
|
117 |
audio = enhance_audio(audio)
|
118 |
audio.export(wav_path, format="wav")
|
119 |
|
120 |
# Konuşmacı ayrımı
|
121 |
+
if diarize:
|
122 |
diarization = diarize_speakers(wav_path)
|
123 |
else:
|
124 |
diarization = None
|
|
|
127 |
result = transcribe_audio(wav_path, diarization)
|
128 |
|
129 |
# Anonimleştirme
|
130 |
+
if anonymize:
|
131 |
result = anonymize_personal_info(result)
|
132 |
|
133 |
# JSON çıktısını hazırla
|
134 |
json_result = {
|
135 |
"transcript": result["text"],
|
136 |
"diarization": diarization,
|
137 |
+
"enhanced_audio": wav_path if enhance else None,
|
138 |
+
"anonymized": anonymize
|
139 |
}
|
140 |
|
141 |
return result["text"], json_result
|