File size: 1,311 Bytes
0dc90fd
457abb4
 
0dc90fd
457abb4
 
 
1ead7c4
457abb4
 
 
 
 
 
1ead7c4
457abb4
 
 
 
 
 
 
 
 
1ead7c4
 
 
457abb4
 
 
 
 
 
 
1ead7c4
457abb4
 
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
import whisper
import os

# Load the Whisper model
model = whisper.load_model("base")  # You can choose "tiny", "small", "medium", or "large"

def transcribe_audio(audio_file, language):
    # Save the uploaded audio file to a temporary location
    temp_file_path = "temp_audio.wav"
    with open(temp_file_path, "wb") as f:
        f.write(audio_file.getbuffer())

    # Transcribe the audio
        result = model.transcribe(temp_file_path, language=language)
    os.remove(temp_file_path)  # Clean up the temporary file
    return result['text']

# Streamlit app layout
st.title("Audio Transcription App")
st.write("Upload an audio file to transcribe it using Whisper.")

# File uploader for audio files
audio_file = st.file_uploader("Choose an audio file", type=["wav", "mp3", "m4a"])
# Language selection
language = st.selectbox("Select Language", options=["en", "es", "fr", "de", "it", "zh"])


if audio_file is not None:
    st.audio(audio_file, format='audio/wav')
    
    # Transcribe the audio when the button is clicked
    if st.button("Transcribe"):
        with st.spinner("Transcribing..."):
            transcription = transcribe_audio(audio_file, language)
        st.success("Transcription complete!")
        st.text_area("Transcription:", transcription, height=300)