Update app.py
Browse files
app.py
CHANGED
@@ -1,54 +1,42 @@
|
|
1 |
import streamlit as st
|
2 |
import speech_recognition as sr
|
3 |
from pydub import AudioSegment
|
4 |
-
import tempfile
|
5 |
-
import os
|
6 |
|
7 |
# Title and description
|
8 |
-
st.title("
|
9 |
-
st.write("Upload an
|
10 |
|
11 |
# Upload an audio file
|
12 |
-
uploaded_audio = st.file_uploader("Upload an
|
13 |
|
14 |
# Input text box
|
15 |
-
input_text = st.text_area("Enter the desired
|
16 |
|
17 |
# Function to trim audio
|
18 |
def trim_audio(input_audio, input_text):
|
19 |
if not input_audio:
|
20 |
return
|
21 |
|
22 |
-
#
|
23 |
-
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
audio_file.write(input_audio.read())
|
30 |
|
31 |
-
|
32 |
-
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
audio = recognizer.record(source)
|
37 |
-
audio_text = recognizer.recognize_google(audio, language="ar-AE")
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
text_to_match = input_text.lower()
|
42 |
-
audio_text = audio_text.lower()
|
43 |
-
|
44 |
-
for word in audio_text.split():
|
45 |
-
if word in text_to_match:
|
46 |
-
trimmed_audio += AudioSegment.from_file(temp_audio_path, format="wav")
|
47 |
-
|
48 |
-
st.audio(trimmed_audio.export(format="wav"), format="audio/wav")
|
49 |
-
|
50 |
-
finally:
|
51 |
-
temp_dir.cleanup()
|
52 |
|
53 |
# Process button
|
54 |
if st.button("Process"):
|
|
|
1 |
import streamlit as st
|
2 |
import speech_recognition as sr
|
3 |
from pydub import AudioSegment
|
|
|
|
|
4 |
|
5 |
# Title and description
|
6 |
+
st.title("Audio Trimming App")
|
7 |
+
st.write("Upload an audio file and enter the desired text. The app will trim the audio to match the specified text.")
|
8 |
|
9 |
# Upload an audio file
|
10 |
+
uploaded_audio = st.file_uploader("Upload an audio file", type=["wav", "mp3"])
|
11 |
|
12 |
# Input text box
|
13 |
+
input_text = st.text_area("Enter the desired text")
|
14 |
|
15 |
# Function to trim audio
|
16 |
def trim_audio(input_audio, input_text):
|
17 |
if not input_audio:
|
18 |
return
|
19 |
|
20 |
+
# Load the audio file and recognize text
|
21 |
+
recognizer = sr.Recognizer()
|
22 |
+
with sr.AudioFile(input_audio) as source:
|
23 |
+
audio = recognizer.record(source)
|
24 |
+
audio_text = recognizer.recognize_google(audio)
|
25 |
|
26 |
+
# Process the audio and create a trimmed audio
|
27 |
+
trimmed_audio = AudioSegment.silent(duration=0)
|
28 |
+
text_to_match = input_text.lower()
|
29 |
+
audio_text = audio_text.lower()
|
|
|
30 |
|
31 |
+
for word in audio_text.split():
|
32 |
+
if word in text_to_match:
|
33 |
+
trimmed_audio += AudioSegment.from_file(input_audio)
|
34 |
|
35 |
+
# Export the trimmed audio to a file
|
36 |
+
trimmed_audio.export("trimmed_audio.mp3", format="mp3")
|
|
|
|
|
37 |
|
38 |
+
# Display the trimmed audio
|
39 |
+
st.audio("trimmed_audio.mp3", format="audio/mp3")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
# Process button
|
42 |
if st.button("Process"):
|