Spaces:
Sleeping
Sleeping
File size: 1,134 Bytes
40cc2a1 d531300 fdcc446 d531300 954468c d531300 954468c d531300 baf5b80 d531300 954468c d531300 044688a e6eb440 e67620f d531300 954468c d531300 5438906 0449dc4 954468c 0449dc4 954468c 0449dc4 954468c 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 |
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")
# Function to convert audio to text
def audio2txt(audioname):
pipe = pipeline("automatic-speech-recognition", model="avery0/pipeline1model2")
rst = pipe(audioname)
return rst['text']
# Function to translate text
def translation(txt):
pipe = pipeline("translation", model= "Helsinki-NLP/opus-mt-en-zh")
rst = pipe(txt)
return rst
# Main function
def main():
uploaded_file = st.file_uploader("Select an audio file", type=["mp3", "wav","m4a"])
if uploaded_file is not None:
audio_data = uploaded_file.read()
st.audio(audio_data, format='audio/mp3/m4a')
# Stage 1: Audio to Text
st.text('Processing audio2txt...')
txt = audio2txt(audio_data)
st.write(txt)
# Stage 2: Text to Translation
st.text('Generating a translation...')
txt2 = translation(txt)
st.write(txt2)
if __name__ == "__main__":
main() |