-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmp3_to_json.py
More file actions
29 lines (20 loc) · 925 Bytes
/
Copy pathmp3_to_json.py
File metadata and controls
29 lines (20 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import whisper
import json
import os
model = whisper.load_model("large-v2")
audios = os.listdir("audios")
for audio in audios:
# print(audio)
if("_" in audio):
number = audio.split("_")[0]
title = audio.split("_")[1][:-4]
print(number, title)
result = model.transcribe(audio = f"audios/{audio}", language = "hi", task = "translate", word_timestamps=False)
# result = model.transcribe(audio = f"audios/sample.mp3", language = "hi", task = "translate", word_timestamps=False)
chunks = []
for segment in result["segments"]:
chunks.append({"number": number, "title": title,"start": segment["start"], "end": segment["end"], "text": segment["text"]})
chunks_with_metadata = {"chunks": chunks, "text": result["text"]}
# print(chunk)
with open(f"jsons/{audio}.json", "w") as f:
json.dump(chunks_with_metadata, f)