-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranscript.py
45 lines (32 loc) · 1.27 KB
/
transcript.py
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 ffmpeg
import whisper
import json
def extract_audio(video_path, output_audio_path):
{
ffmpeg.input(video_path)
.output(output_audio_path)
.run()
}
def transcribe(video_path, audio_path, transcript_path):
extract_audio(video_path, audio_path)
# Load the Whisper model
model = whisper.load_model("base")
# Process the audio file and generate the transcription
result = model.transcribe(audio_path)
with open(transcript_path, 'w', encoding='utf-8') as file:
json.dump(result, file, ensure_ascii=False, indent=4)
# Return the transcription text
return result
def transcribe_audio(audio_path, transcript_path):
# Load the Whisper model
model = whisper.load_model("base")
# Process the audio file and generate the transcription
result = model.transcribe(audio_path)
with open(transcript_path, 'w', encoding='utf-8') as file:
json.dump(result, file, ensure_ascii=False, indent=4)
# Return the transcription text
return result
#extract_audio('static/stylerVideo.mp4', 'audio-files/VideoAudio.wav')
transcribe_audio('audio-files/VideoAudio.wav', 'audio-files/VidTranscript.json')
# transcript = transcribe_audio('audio-files/NeuralNetAudio.wav', 'audio-files/VidTranscript.txt')
# print(transcript)