Update README.md
Browse files
README.md
CHANGED
@@ -43,26 +43,47 @@ how to use the model in colab:
|
|
43 |
audio.export(wav_path, format="wav")
|
44 |
return wav_path
|
45 |
|
46 |
-
#
|
47 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
wav_path = convert_to_wav(audio_path)
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
# Save transcription to a text file
|
53 |
text_path = "transcription.txt"
|
54 |
with open(text_path, "w") as f:
|
55 |
-
f.write(
|
56 |
|
57 |
return text_path
|
58 |
|
59 |
# Upload and process audio in Colab
|
60 |
uploaded = files.upload()
|
61 |
audio_file = list(uploaded.keys())[0]
|
62 |
-
transcription_file =
|
63 |
|
64 |
# Download the transcription file
|
65 |
files.download(transcription_file)
|
66 |
|
67 |
|
68 |
|
|
|
|
43 |
audio.export(wav_path, format="wav")
|
44 |
return wav_path
|
45 |
|
46 |
+
# Split long audio into chunks
|
47 |
+
def split_audio(audio_path, chunk_length_ms=30000): # Default: 30 sec per chunk
|
48 |
+
audio = AudioSegment.from_wav(audio_path)
|
49 |
+
chunks = [audio[i:i+chunk_length_ms] for i in range(0, len(audio), chunk_length_ms)]
|
50 |
+
chunk_paths = []
|
51 |
+
|
52 |
+
for i, chunk in enumerate(chunks):
|
53 |
+
chunk_path = f"chunk_{i}.wav"
|
54 |
+
chunk.export(chunk_path, format="wav")
|
55 |
+
chunk_paths.append(chunk_path)
|
56 |
+
|
57 |
+
return chunk_paths
|
58 |
+
|
59 |
+
# Transcribe a long audio file
|
60 |
+
def transcribe_long_audio(audio_path):
|
61 |
wav_path = convert_to_wav(audio_path)
|
62 |
+
chunk_paths = split_audio(wav_path)
|
63 |
+
transcription = ""
|
64 |
+
|
65 |
+
for chunk in chunk_paths:
|
66 |
+
result = whisper_pipe(chunk)
|
67 |
+
transcription += result["text"] + "\n"
|
68 |
+
os.remove(chunk) # Remove processed chunk
|
69 |
+
|
70 |
+
os.remove(wav_path) # Cleanup original file
|
71 |
|
72 |
# Save transcription to a text file
|
73 |
text_path = "transcription.txt"
|
74 |
with open(text_path, "w") as f:
|
75 |
+
f.write(transcription)
|
76 |
|
77 |
return text_path
|
78 |
|
79 |
# Upload and process audio in Colab
|
80 |
uploaded = files.upload()
|
81 |
audio_file = list(uploaded.keys())[0]
|
82 |
+
transcription_file = transcribe_long_audio(audio_file)
|
83 |
|
84 |
# Download the transcription file
|
85 |
files.download(transcription_file)
|
86 |
|
87 |
|
88 |
|
89 |
+
|