57 lines
2.5 KiB
Python
57 lines
2.5 KiB
Python
from speechlib import Transcriptor
|
|
from configparser import ConfigParser
|
|
import os
|
|
import streamlit as st
|
|
import tempfile
|
|
|
|
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
|
|
|
|
def str2bool(v):
|
|
return v.lower() in ("yes", "true", "t", "1")
|
|
|
|
config = ConfigParser()
|
|
config.read('config.ini')
|
|
audiofolder = config.get('FILE', 'audiofolder')
|
|
access_token = config.get('FILE', 'accesstoken')
|
|
voicefolder = config.get('FILE', 'voicefolder')
|
|
outputfolder = config.get('FILE', 'outputfolder')
|
|
language = "id"
|
|
quantization = str2bool(config.get('FILE', 'quantization'))
|
|
modelSize = "medium"
|
|
|
|
st.title("Crew Transcription")
|
|
|
|
audio = st.file_uploader("Upload audio file (.mp3/.wav/.m4a)", type=["mp3", "wav", "m4a"])
|
|
crew_id = st.text_input("Crew ID")
|
|
crew_name = st.text_input("Crew Name")
|
|
outlet = st.selectbox('Outlet',('Icon Mall','Kediri','Ponti','Plaza Surabaya Delta','AEON','Rungkut','Darmo','Royal Plaza',
|
|
'Kusuma Bangsa','Sepanjang','Barata','Pakuwon City Mall','Tropodo','Wiyung','Citraland',
|
|
'Lotte Avenue','Pakuwon Trade Center','Rest Area Sidoarjo','Gayungsari','Wahidin','Imam Bonjol',
|
|
'BG Junction','Puri Surya Jaya','Merr','Karawaci','Pepelegi','Plaza Festival'
|
|
))
|
|
date = st.date_input("Date")
|
|
if st.button("Transcribe"):
|
|
if audio is not None and crew_id:
|
|
with st.spinner("Transcribing..."):
|
|
# Save the uploaded audio file to a temporary location
|
|
file_details = {"filename": audio.name, "filetype": audio.type, "filesize": audio.size}
|
|
print(file_details)
|
|
|
|
temp_dir = tempfile.mkdtemp()
|
|
path = os.path.join(temp_dir, audio.name)
|
|
|
|
with open(path, "wb") as f:
|
|
f.write(audio.getvalue())
|
|
print(f"Temporary file saved at: {path}")
|
|
|
|
#audiofilewithoutextension = path.split(".mp3")[0].split(".wav")[0].split(".m4a")[0]
|
|
#filepath = os.path.join(outputfolder, os.path.basename(audiofilewithoutextension).split('/')[-1]+".txt")
|
|
filepath = os.path.join(outputfolder, f"{outlet}-{crew_id}-{crew_name}-{date}-Transkrip.txt")
|
|
print(f"Output file: {filepath}")
|
|
filename = open(filepath, "w")
|
|
|
|
### transcribe ###
|
|
transcriptor = Transcriptor(path, filepath, language, modelSize, access_token, voicefolder, quantization)
|
|
res = transcriptor.faster_whisper()
|
|
print(f"Content has been written to {filepath}")
|
|
st.success(f"Transcribe successful!") |