-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrans.py
35 lines (28 loc) · 828 Bytes
/
trans.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
import numpy as np
import whisper
import warnings
import sys
from os import system, devnull
warnings.simplefilter("ignore")
#Audio as Argument
def argument():
if len(sys.argv) < 2:
print("Usage: python3 trans.py [audio_file]")
model = whisper.load_model("base")
if len(sys.argv) <2:
print("Error: No audio file specified.")
sys.exit(1)
audio = sys.argv[1]
transcription = model.transcribe(audio)
sys("clear")
for sentennce in transcription["segments"]:
print(sentennce["text"])
#Audio as Input
def transcribe(audio_file):
model = whisper.load_model("base")
transcription = model.transcribe(audio_file)
frase = ""
for sentence in transcription["segments"]:
frase += sentence["text"]
print(f"\nFrase: {frase}\n" )
return frase