Skip to content

Commit a6dd3d6

Browse files
committed
feat: add multiple audio files handling
1 parent 8f5c9ce commit a6dd3d6

14 files changed

Lines changed: 174 additions & 258 deletions

File tree

.gitignore

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Artifacts
12
__pycache__
23
.ipynb_checkpoints/
34
.DS_Store
@@ -14,13 +15,14 @@ venv
1415
build/
1516
dist/
1617
_version.py
18+
19+
# Media and output
1720
*.txt
18-
!testing_audio.txt
1921
*.srt
20-
!testing_audio.srt
2122
*.wav
22-
!testing_audio.wav
2323
*.mp3
24-
!testing_audio.mp3
2524
*.m4a
26-
!testing_audio.m4a
25+
!test0*
26+
27+
# Deprecated
28+
requirements.txt

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ execute()
3737

3838
### Python API
3939
```python
40-
from ghe_transcribe.core import transcribe_core
41-
result = transcribe_core("path/to/audio.mp3")
40+
from ghe_transcribe.core import transcribe
41+
result = transcribe("path/to/audio.mp3")
4242
```
4343

4444
### Command Line

media/test02.m4a

531 KB
Binary file not shown.

media/testing_audio.wav

-1.36 MB
Binary file not shown.

output/test02.srt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
1
2+
00:00:00,640 --> 00:00:08,960
3+
S00: So hi Fiona, we're here to record an audio that I will use for testing.
4+
5+
2
6+
00:00:10,400 --> 00:00:17,600
7+
S01: Hi Nicolo, thanks so much for the honor to invite me to help you on this project.
8+
9+
3
10+
00:00:18,240 --> 00:00:34,160
11+
S00: You're welcome, you were the first person that came to mind. So we're here to ask you a couple of questions until we reach minute one. So what do you do in life Fiona?
12+
13+
4
14+
00:00:34,160 --> 00:00:44,400
15+
S02: Good question, good question. So at the moment I do an internship, it's going great, everything I do is productive, will be published probably by tomorrow.
16+
17+
5
18+
00:00:46,400 --> 00:00:53,280
19+
S02: Yeah, just doing the grind, just yeah. Of course. Do you have plans for lunch?
20+
21+
6
22+
00:00:53,280 --> 00:00:56,560
23+
S02: Plans for lunch? Yes, actually I do, I'm meeting a friend.
24+
25+
7
26+
00:00:56,560 --> 00:01:02,400
27+
S02: If you want, you're welcome to join. Perfect, thank you very much.

output/test02.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
S00: [00:00:00] So hi Fiona, we're here to record an audio that I will use for testing.
2+
S01: [00:00:10] Hi Nicolo, thanks so much for the honor to invite me to help you on this project.
3+
S00: [00:00:18] You're welcome, you were the first person that came to mind. So we're here to ask you a couple of questions until we reach minute one. So what do you do in life Fiona?
4+
S02: [00:00:34] Good question, good question. So at the moment I do an internship, it's going great, everything I do is productive, will be published probably by tomorrow.
5+
S02: [00:00:46] Yeah, just doing the grind, just yeah. Of course. Do you have plans for lunch?
6+
S02: [00:00:53] Plans for lunch? Yes, actually I do, I'm meeting a friend.
7+
S02: [00:00:56] If you want, you're welcome to join. Perfect, thank you very much.

src/ghe_transcribe/app.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
ComputeTypeChoice, # Enum for compute type choices
1818
DeviceChoice, # Enum for device choices
1919
WhisperModelChoice, # Enum for Whisper model choices
20+
transcribe,
2021
transcribe_config, # Default configuration
21-
transcribe_core,
2222
)
2323
from ghe_transcribe.utils import log_hf_authentication_error, save_uploaded_file
2424

@@ -146,7 +146,7 @@ def _setup_ui(self):
146146
"""Defines all the UI widgets and their initial layout."""
147147
# Basic Options
148148
self.audio_uploader = widgets.FileUpload(
149-
multiple=False,
149+
multiple=True,
150150
description="Upload Audio",
151151
# accept=".wav, .m4a, .mp3, .flac, .ogg", # Specify accepted audio formats
152152
layout=self.common_widget_layout,
@@ -369,21 +369,26 @@ def _on_run_button_click(self, b):
369369
return
370370

371371
try:
372-
# Handle uploaded file
373-
file_metadata = self.audio_uploader.value[0]
374-
uploaded_file_name = file_metadata["name"]
375-
uploaded_content_bytes = file_metadata["content"].tobytes()
376-
377-
# Save uploaded file using modern path handling
378-
audio_file_path = save_uploaded_file(
379-
uploaded_file_name, uploaded_content_bytes
380-
)
381-
logger.info(f"Uploaded audio saved to: {audio_file_path}")
382-
print(f"Uploaded audio saved to: {audio_file_path}")
372+
# Handle uploaded files (single or multiple)
373+
uploaded_files = []
374+
for file_metadata in self.audio_uploader.value:
375+
uploaded_file_name = file_metadata["name"]
376+
uploaded_content_bytes = file_metadata["content"].tobytes()
377+
378+
# Save uploaded file using modern path handling
379+
audio_file_path = save_uploaded_file(
380+
uploaded_file_name, uploaded_content_bytes
381+
)
382+
uploaded_files.append(str(audio_file_path))
383+
logger.info(f"Uploaded audio saved to: {audio_file_path}")
384+
print(f"Uploaded audio saved to: {audio_file_path}")
385+
386+
# Determine if single file or multiple files
387+
files_input = uploaded_files[0] if len(uploaded_files) == 1 else uploaded_files
383388

384389
# Prepare arguments for transcribe
385390
kwargs = {
386-
"file": str(audio_file_path),
391+
"files": files_input,
387392
"trim": self.trim_input.value
388393
if self.trim_input.value > 0
389394
else None,
@@ -413,7 +418,7 @@ def _on_run_button_click(self, b):
413418
kwargs["max_speakers"] = self.max_speakers_input.value
414419

415420
# Call the ghe_transcribe function
416-
transcribe_core(**kwargs)
421+
transcribe(**kwargs)
417422

418423
except Exception as e:
419424
logger.error(f"An unexpected error occurred: {e}", exc_info=True)

0 commit comments

Comments
 (0)