Rhueue commited on
Commit
7cd88dd
·
1 Parent(s): 83db5aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -37
app.py CHANGED
@@ -1,43 +1,43 @@
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"):
43
- trim_audio(uploaded_audio, input_text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import speech_recognition as sr
 
3
 
4
+ def transcribe_audio(audio_file):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  recognizer = sr.Recognizer()
 
 
 
6
 
7
+ with sr.AudioFile(audio_file) as source:
8
+ audio = recognizer.record(source)
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ try:
11
+ transcription = recognizer.recognize_google(audio)
12
+ return transcription
13
+ except sr.UnknownValueError:
14
+ return ""
15
+
16
+ def filter_words(input_text, transcribed_text):
17
+ transcribed_words = transcribed_text.split()
18
+ filtered_text = input_text
19
+ for word in transcribed_words:
20
+ filtered_text = filtered_text.replace(word, "")
21
+ return filtered_text
22
+
23
+ st.title("Voice Cloning Word Filter")
24
+
25
+ uploaded_audio = st.file_uploader("Upload an audio file", type=["wav", "mp3", "ogg"])
26
+ input_text = st.text_area("Enter input text")
27
+
28
+ if uploaded_audio is not None:
29
+ st.audio(uploaded_audio, format="audio/wav")
30
+
31
+ if st.button("Transcribe and Filter"):
32
+ if uploaded_audio is not None:
33
+ transcribed_text = transcribe_audio(uploaded_audio)
34
+ filtered_text = filter_words(input_text, transcribed_text)
35
+ st.subheader("Transcribed Text:")
36
+ st.write(transcribed_text)
37
+ st.subheader("Filtered Output Text:")
38
+ st.write(filtered_text)
39
+
40
+ st.write(
41
+ "Note: This is a simple demonstration of filtering words from an audio transcript. The accuracy of word filtering "
42
+ "depends on the quality of the audio and the performance of the ASR engine."
43
+ )