Basic App.py
Browse files
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torchaudio as ta
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
from io import BytesIO
|
5 |
+
from transformers import AutoProcessor, SeamlessM4TModel
|
6 |
+
|
7 |
+
processor = AutoProcessor.from_pretrained("facebook/hf-seamless-m4t-medium", use_fast=False)
|
8 |
+
model = SeamlessM4TModel.from_pretrained("facebook/hf-seamless-m4t-medium")
|
9 |
+
|
10 |
+
# Title of the app
|
11 |
+
st.title("Audio Player with Live Transcription")
|
12 |
+
|
13 |
+
# Sidebar for file uploader and submit button
|
14 |
+
st.sidebar.header("Upload Audio Files")
|
15 |
+
uploaded_files = st.sidebar.file_uploader("Choose audio files", type=["mp3", "wav"], accept_multiple_files=True)
|
16 |
+
submit_button = st.sidebar.button("Submit")
|
17 |
+
|
18 |
+
|
19 |
+
# def transcribe_audio(audio_data):
|
20 |
+
# recognizer = sr.Recognizer()
|
21 |
+
# with sr.AudioFile(audio_data) as source:
|
22 |
+
# audio = recognizer.record(source)
|
23 |
+
# try:
|
24 |
+
# # Transcribe the audio using Google Web Speech API
|
25 |
+
# transcription = recognizer.recognize_google(audio)
|
26 |
+
# return transcription
|
27 |
+
# except sr.UnknownValueError:
|
28 |
+
# return "Unable to transcribe the audio."
|
29 |
+
# except sr.RequestError as e:
|
30 |
+
# return f"Could not request results; {e}"
|
31 |
+
|
32 |
+
|
33 |
+
if submit_button and uploaded_files:
|
34 |
+
st.write("Files uploaded successfully!")
|
35 |
+
|
36 |
+
for uploaded_file in uploaded_files:
|
37 |
+
# Display file name and audio player
|
38 |
+
print(uploaded_file)
|
39 |
+
st.write(f"**File name**: {uploaded_file.name}")
|
40 |
+
st.audio(uploaded_file, format=uploaded_file.type)
|
41 |
+
|
42 |
+
# Transcription section
|
43 |
+
st.write("**Transcription**:")
|
44 |
+
|
45 |
+
# Read the uploaded file data
|
46 |
+
waveform, sampling_rate = ta.load(uploaded_file.getvalue())
|
47 |
+
|
48 |
+
# Run transcription function and display
|
49 |
+
# import pdb;pdb.set_trace()
|
50 |
+
# st.write(audio_data.getvalue())
|
51 |
+
|