audio_translate / app.py
sss2000's picture
Update app.py
40cc2a1 verified
raw
history blame
1.17 kB
import streamlit as st
from transformers import pipeline
st.set_page_config(page_title="Your English audio to Chinese text,
page_icon="🦜")
st.header("Turn Your English Audio to Chinese text")
uploaded_file = st.file_uploader("Select an audio file",type=["mp3","mp4"])
if uploaded_file is not None:
print(uploaded_file)
bytes_data = uploaded_file.getvalue()
with open(uploaded_file.name, "wb") as file:
file.write(bytes_data)
st.image(uploaded_file, caption="Uploaded Audio",
use_column_width=True)
# function part
def audio2txt(audioname):
pipe = pipeline("Automatic-Speech-Recognition", model="avery0/pipeline1model2")
rst = pipe(audioname)
return rst
def translation(txt):
pipe = pipeline(model="translation", model="DDDSSS/translation_en-zh")
rst = pipe(txt)
return rst
def main():
#Stage 1: Aido to Text
st.text('Processing audio2txt...')
txt = audio2txt(uploaded_file.name)
st.write(txt)
#Stage 2: Text to Story
st.text('Generating a translation...')
txt2 = translation(txt)
st.write(txt2)
# main part
if __name__ == "__main__":
main()