File size: 913 Bytes
ffe71b0
 
 
30f568b
 
ffe71b0
 
 
 
 
 
 
 
 
 
 
 
 
30f568b
 
 
ffe71b0
30f568b
ffe71b0
 
 
 
30f568b
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
import streamlit as st
import stable_whisper
import json
import soundfile as sf
import io

# Create a dropdown to select the model
model_name = st.selectbox("Select a model", ["base", "small", "medium", "large", "large-v2"])

# Load the selected model
model = stable_whisper.load_model(model_name)

# Create a file uploader for the audio file
audiofile = st.file_uploader("Upload an audio file", type=["mp3", "wav"])

# Create a button to run the prediction
if st.button('Transcribe'):
    if audiofile is not None:
        # Read the audio file
        file_bytes = audiofile.read()
        audio_data, sample_rate = sf.read(io.BytesIO(file_bytes))
        # Transcribe the audio file
        result = model.transcribe(audio_data)
        # Convert the result to JSON and display it
        result_json = json.loads(result)
        st.json(result_json)
    else:
        st.write("Please upload an audio file.")