File size: 1,431 Bytes
ec2398c
 
 
e0bc8d0
ec2398c
 
 
e0bc8d0
 
 
 
 
 
 
 
ec2398c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
import os

import whisper
import torch
import time
def transcribe_segments(speakers):
    print(f"Whisper models {whisper.available_models()}")
    if torch.cuda.is_available():
        print("transcribe_segments Using CUDA")
        device = "cuda"
    else:
        device = "cpu"
        print("transcribe_segments Using CPU")

    model = whisper.load_model("tiny.en", device=device)
    #model = whisper.load_model("medium.en", device="cuda")
#    model = whisper.load_model("turbo", device="cuda")
    #model = whisper.load_model("large-v3-turbo", device="cuda")
    transcripts = []
    input_file = ""
    print("Transcribing ALL segments")
    total_start = time.time()
    for speaker in speakers:
        # {'speaker': speaker, 'start': round(turn.start, 1),
        #  'end': round(turn.end, 1), 'clipFile':clipName}
        input_file = speaker['clipFile']

        print("TRANSCRIBING " + input_file)
        start = time.time()
        transcript = model.transcribe(input_file)
        print("Elapsed " + str(time.time() - start))
        segments = transcript["segments"]
        outText = ""
        for segment in segments:
            outText += segment['text']

        transcripts.append(speaker['speaker']+" : "+outText)
        os.remove(input_file)

    print("Total Elapsed " + str(time.time() - total_start))
    currdir= input_file[0:input_file.index('\\')]
    os.rmdir(currdir)

    return transcripts