Spaces:
Runtime error
Runtime error
File size: 972 Bytes
931df81 |
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 30 31 32 33 |
import whisper
import torch
import gc
import json
gc.collect()
torch.cuda.empty_cache()
device = torch.device("cuda")
model = whisper.load_model("medium", device=device)
def start_transcribe(progress):
sample_groups, speaker_groups = load_groups_json()
for speaker in speaker_groups:
# Transcribe and save temp file
audiof = f"{speaker}.wav"
print(f"Loading {audiof}")
result = model.transcribe(
audio=audiof, language='id', word_timestamps=True)
with open(f"{speaker}.json", "w") as text_file:
json.dump(result, text_file, indent=4)
return result['text']
def load_groups_json():
with open("sample_groups.json", "r") as json_file_sample:
sample_groups_list: list = json.load(json_file_sample)
with open("speaker_groups.json", "r") as json_file_speaker:
speaker_groups_dict: dict = json.load(json_file_speaker)
return sample_groups_list, speaker_groups_dict
|