muzammil-eds commited on
Commit
8b6c021
·
verified ·
1 Parent(s): 18922c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -23
app.py CHANGED
@@ -40,27 +40,41 @@ def evaluate_audio_similarity(original_audio_bytes, user_audio_bytes):
40
 
41
  st.title("Audio Transcription and Similarity Checker")
42
 
43
- # Choose between upload or record
44
- st.sidebar.header("Input Method")
45
- input_method = st.sidebar.selectbox("Choose Input Method", ["Record"])
46
-
47
- original_audio_bytes = None
48
- user_audio_bytes = None
49
-
50
- # Delay for initial setup to avoid first-click auto-stop issue
51
- if input_method == "Record":
52
- st.write("Record or Upload Original Audio")
53
-
54
- # Introducing a delay for initial recording setup to avoid immediate stop issue
55
- if 'initialized' not in st.session_state:
56
- st.session_state['initialized'] = False
57
-
58
- if not st.session_state['initialized']:
 
 
 
59
  st.session_state['initialized'] = True
60
- st.warning("Initializing recorder... Please wait a moment.")
61
- time.sleep(2) # Add small delay before first-time recording
62
- else:
63
- original_audio_bytes = audio_recorder(key="original_audio_recorder", pause_threshold=30, icon_size='4x')
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  if not original_audio_bytes:
66
  original_audio = st.file_uploader("Or Upload Original Audio", type=["wav", "mp3"])
@@ -71,8 +85,19 @@ if input_method == "Record":
71
  with st.spinner("Processing original audio..."):
72
  st.audio(original_audio_bytes, format="audio/wav")
73
 
74
- st.write("Record or Upload User Audio")
75
- user_audio_bytes = audio_recorder(key="user_audio_recorder", pause_threshold=30, icon_size='4x')
 
 
 
 
 
 
 
 
 
 
 
76
 
77
  if not user_audio_bytes:
78
  user_audio = st.file_uploader("Or Upload User Audio", type=["wav", "mp3"])
@@ -96,7 +121,7 @@ if input_method == "Record":
96
  st.write(f"**User Transcription:** {transcription_user}")
97
  st.write(f"**Levenshtein Similarity Score:** {similarity_score:.2f}")
98
 
99
- if similarity_score > 0.8:
100
  st.success("The pronunciation is likely correct based on transcription similarity.")
101
  else:
102
  st.error("The pronunciation may be incorrect based on transcription similarity.")
 
40
 
41
  st.title("Audio Transcription and Similarity Checker")
42
 
43
+ # Initialize the session state to control the view
44
+ if 'initialized' not in st.session_state:
45
+ st.session_state['initialized'] = False
46
+
47
+ # Button to initialize the recorders
48
+ if not st.session_state['initialized']:
49
+
50
+ st.write("Click the Loader below to initialize the audio recorders.")
51
+
52
+ if st.button('Click to start recording'):
53
+ init_button = audio_recorder(
54
+ text="",
55
+ recording_color="#e8b62c",
56
+ neutral_color="#6aa36f",
57
+ pause_threshold=0.1,
58
+ icon_name="", # You can change this to any Font Awesome solid icon
59
+ icon_size="4x",
60
+ auto_start=True
61
+ )
62
  st.session_state['initialized'] = True
63
+
64
+ # If initialized, display the recorders
65
+ if st.session_state['initialized']:
66
+
67
+ st.subheader("Record or Upload Original Audio")
68
+
69
+ # Style the record button with the provided parameters
70
+ original_audio_bytes = audio_recorder(
71
+ text="Click to Record Audio",
72
+ recording_color="#e8b62c",
73
+ neutral_color="#6aa36f",
74
+ pause_threshold=30,
75
+ icon_name="microphone", # You can change this to any Font Awesome solid icon
76
+ icon_size="4x"
77
+ )
78
 
79
  if not original_audio_bytes:
80
  original_audio = st.file_uploader("Or Upload Original Audio", type=["wav", "mp3"])
 
85
  with st.spinner("Processing original audio..."):
86
  st.audio(original_audio_bytes, format="audio/wav")
87
 
88
+ st.subheader("Record or Upload User Audio")
89
+
90
+ st.write("")
91
+
92
+ # Style the user audio recorder similarly
93
+ user_audio_bytes = audio_recorder(
94
+ text="Click to Record Audio",
95
+ recording_color="#e86f6f",
96
+ neutral_color="#6a6faf",
97
+ pause_threshold=30,
98
+ icon_name="user", # You can change this to any Font Awesome solid icon
99
+ icon_size="4x"
100
+ )
101
 
102
  if not user_audio_bytes:
103
  user_audio = st.file_uploader("Or Upload User Audio", type=["wav", "mp3"])
 
121
  st.write(f"**User Transcription:** {transcription_user}")
122
  st.write(f"**Levenshtein Similarity Score:** {similarity_score:.2f}")
123
 
124
+ if similarity_score > 0.8: # Adjust the threshold as needed
125
  st.success("The pronunciation is likely correct based on transcription similarity.")
126
  else:
127
  st.error("The pronunciation may be incorrect based on transcription similarity.")