File size: 1,155 Bytes
40cc2a1
fdcc446
d531300
 
fdcc446
d531300
2256efc
d531300
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import gradio as gr
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")

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()