chandralegend commited on
Commit
3291d28
1 Parent(s): 917de57

audio record

Browse files
pages/4_Trying Out(Guess the Phrase).py CHANGED
@@ -3,6 +3,7 @@ from utils.levels import complete_level, render_page, initialize_level
3
  from utils.login import initialize_login, get_login
4
  import requests
5
  import os
 
6
 
7
 
8
  def check_sentence_similarity(source_sentence, sentence):
@@ -36,28 +37,42 @@ initialize_level()
36
  def step_page():
37
  st.header("Tryit Out")
38
 
39
- uploaded_file = st.file_uploader("Upload a file", type=["wav", "mp3", "flac"])
40
- if uploaded_file:
41
- audio_file = os.path.join(".sessions", get_login()["username"], "audio.flac")
42
- with open(audio_file, "wb") as f:
43
- f.write(uploaded_file.getbuffer())
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  else:
45
  audio_file = "assets/sample1.flac"
46
 
47
- st.audio(audio_file, format="audio/flac")
 
48
 
49
- transcript = st.text_input("What did you hear?")
50
- if st.button("Check") and transcript:
51
- with st.spinner("Checking..."):
52
- output = get_audio_transcription(audio_file)
53
- similarity = check_sentence_similarity(output["text"], transcript)
54
- if similarity > 0.75:
55
- st.success(
56
- f"Correct! You are {similarity * 100}% similar to the original sentence."
57
- )
58
- else:
59
- st.error("You are not similar enough to the original sentence.")
60
- st.info(f"Original sentence: {output['text']}")
61
 
62
 
63
  render_page(step_page, LEVEL)
 
3
  from utils.login import initialize_login, get_login
4
  import requests
5
  import os
6
+ from audio_recorder_streamlit import audio_recorder
7
 
8
 
9
  def check_sentence_similarity(source_sentence, sentence):
 
37
  def step_page():
38
  st.header("Tryit Out")
39
 
40
+ input_type = st.selectbox("Input Type", ["Upload", "Record", "Sample"], index=2)
41
+ audio_file = None
42
+ if input_type == "Upload":
43
+ uploaded_file = st.file_uploader("Upload a file", type=["wav", "mp3", "flac"])
44
+ if uploaded_file:
45
+ audio_file = os.path.join(
46
+ ".sessions", get_login()["username"], "audio.flac"
47
+ )
48
+ with open(audio_file, "wb") as f:
49
+ f.write(uploaded_file.getbuffer())
50
+ elif input_type == "Record":
51
+ audio_bytes = audio_recorder()
52
+ if audio_bytes:
53
+ audio_file = os.path.join(
54
+ ".sessions", get_login()["username"], "audio.flac"
55
+ )
56
+ with open(audio_file, "wb") as f:
57
+ f.write(audio_bytes)
58
  else:
59
  audio_file = "assets/sample1.flac"
60
 
61
+ if audio_file:
62
+ st.audio(audio_file, format="audio/flac")
63
 
64
+ transcript = st.text_input("What did you hear?")
65
+ if st.button("Check") and transcript:
66
+ with st.spinner("Checking..."):
67
+ output = get_audio_transcription(audio_file)
68
+ similarity = check_sentence_similarity(output["text"], transcript)
69
+ if similarity > 0.75:
70
+ st.success(
71
+ f"Correct! You are {similarity * 100}% similar to the original sentence."
72
+ )
73
+ else:
74
+ st.error("You are not similar enough to the original sentence.")
75
+ st.info(f"Original sentence: {output['text']}")
76
 
77
 
78
  render_page(step_page, LEVEL)
utils/login.py CHANGED
@@ -15,11 +15,6 @@ def initialize_login():
15
 
16
  if st.button("Login"):
17
  authorized = authenticate(username, password)
18
- authorized = {
19
- "status": True,
20
- "username": "admin",
21
- "Name": "Admin",
22
- }
23
  if authorized["status"]:
24
  st.session_state["login"] = authorized
25
  os.makedirs(
 
15
 
16
  if st.button("Login"):
17
  authorized = authenticate(username, password)
 
 
 
 
 
18
  if authorized["status"]:
19
  st.session_state["login"] = authorized
20
  os.makedirs(