-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeech2text.py
More file actions
24 lines (19 loc) · 873 Bytes
/
Copy pathspeech2text.py
File metadata and controls
24 lines (19 loc) · 873 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
from datetime import timedelta
import os
import whisper
def get_user_transcript(recordTimetamp, username, file):
userTranscript = {}
model = whisper.load_model("small")
transcription = model.transcribe(file, fp16=False)
for transcript in transcription['segments']:
second = int(transcript['start'])
microsecond = int((transcript['start'] - second) * 1e6)
delta = timedelta(seconds=second, microseconds=microsecond)
timestamp = recordTimetamp + delta
key = f"{timestamp.strftime('%H:%M:%S.%f')} @{username}"
userTranscript.update({key: transcript['text'].strip()})
return userTranscript
def compile_user_transcript(userTranscripts, dir):
with open(os.path.join(dir, 'transcript.txt'), 'w') as file:
for timestamp, text in userTranscripts:
file.write(f'{timestamp}: {text}\n')