Update app.py
Browse files
app.py
CHANGED
@@ -51,7 +51,7 @@ def create_subtitle_file(timestamps_with_text, output_path, format_type="srt"):
|
|
51 |
f.write(f"{text}\n\n")
|
52 |
|
53 |
def create_preview_html(audio_path, vtt_path):
|
54 |
-
"""Create an HTML preview
|
55 |
static_dir = Path("static")
|
56 |
static_dir.mkdir(exist_ok=True)
|
57 |
|
@@ -64,20 +64,19 @@ def create_preview_html(audio_path, vtt_path):
|
|
64 |
shutil.copy2(audio_path, new_audio_path)
|
65 |
shutil.copy2(vtt_path, new_vtt_path)
|
66 |
|
67 |
-
#
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
-
|
72 |
-
html_content = html_content.replace("{{ audio_path }}", f"static/{audio_filename}")
|
73 |
-
html_content = html_content.replace("{{ vtt_path }}", f"static/{vtt_filename}")
|
74 |
-
|
75 |
-
# Save preview HTML
|
76 |
-
preview_path = static_dir / "preview.html"
|
77 |
-
with open(preview_path, "w") as f:
|
78 |
-
f.write(html_content)
|
79 |
-
|
80 |
-
return str(preview_path)
|
81 |
|
82 |
def transcribe_with_vad(audio_path):
|
83 |
# Load and resample audio to 16kHz mono
|
@@ -137,4 +136,4 @@ demo = gr.Interface(
|
|
137 |
)
|
138 |
|
139 |
if __name__ == "__main__":
|
140 |
-
demo.launch(share=True)
|
|
|
51 |
f.write(f"{text}\n\n")
|
52 |
|
53 |
def create_preview_html(audio_path, vtt_path):
|
54 |
+
"""Create an HTML preview with audio player and subtitles"""
|
55 |
static_dir = Path("static")
|
56 |
static_dir.mkdir(exist_ok=True)
|
57 |
|
|
|
64 |
shutil.copy2(audio_path, new_audio_path)
|
65 |
shutil.copy2(vtt_path, new_vtt_path)
|
66 |
|
67 |
+
# Create direct HTML content
|
68 |
+
html_content = f"""
|
69 |
+
<div class="player-container">
|
70 |
+
<h3>Audio Player with Subtitles</h3>
|
71 |
+
<audio controls style="width: 100%; margin: 10px 0;">
|
72 |
+
<source src="file/{new_audio_path}" type="audio/wav">
|
73 |
+
<track label="English" kind="subtitles" srclang="en" src="file/{new_vtt_path}" default>
|
74 |
+
Your browser does not support the audio element.
|
75 |
+
</audio>
|
76 |
+
</div>
|
77 |
+
"""
|
78 |
|
79 |
+
return html_content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
def transcribe_with_vad(audio_path):
|
82 |
# Load and resample audio to 16kHz mono
|
|
|
136 |
)
|
137 |
|
138 |
if __name__ == "__main__":
|
139 |
+
demo.launch(share=True, file_directories=["static"])
|