amkj84 commited on
Commit
2691203
·
verified ·
1 Parent(s): 0acd79f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import streamlit as st
2
- from keyboard import on_press, wait
 
 
3
 
4
  # Define voice, speed, and pitch variables (initial values)
5
  voice = "en" # English (change for other voices)
@@ -7,25 +9,25 @@ speed = 1.0
7
  pitch = 1.0
8
 
9
  # (Optional) Text pre-processing function (customize for specific needs)
10
- def preprocess_text(key):
11
- pressed_key = str(key).replace("'", "")
12
- return pressed_key
13
 
14
- # Function to handle key presses and trigger text-to-speech
15
- def on_press_wrapper(key):
16
  global voice, speed, pitch
17
 
18
  # Call pre-processing function (if implemented)
19
- text = preprocess_text(key)
20
 
21
  # Simulate text input to a text-to-speech API (replace with your chosen API)
22
  # This example demonstrates a basic placeholder
23
- print(f"Simulating text input to TTS API: {text} (Voice: {voice}, Speed: {speed}, Pitch: {pitch})")
24
 
25
  # You'll need to integrate your chosen text-to-speech API here
26
 
27
  # Streamlit App
28
- st.title("Text-to-Speech Keystroke Announcer (Headless)")
29
 
30
  # User Interface for customization options
31
  voice_selected = st.selectbox("Voice", ["en", "fr", "es"]) # Add more options
@@ -37,9 +39,11 @@ voice = voice_selected
37
  speed = speed_slider
38
  pitch = pitch_slider
39
 
40
- # Start keystroke listener on button press
41
- if st.button("Start Keystroke Announcer"):
42
- on_press(on_press_wrapper)
43
- wait() # Block execution until the listener is stopped
 
 
44
 
45
- st.write("Press 'Esc' to stop keystroke detection (simulated).")
 
1
  import streamlit as st
2
+
3
+ # Text input for user to type keystrokes
4
+ key_input = st.text_input("Enter Keystroke:", key="")
5
 
6
  # Define voice, speed, and pitch variables (initial values)
7
  voice = "en" # English (change for other voices)
 
9
  pitch = 1.0
10
 
11
  # (Optional) Text pre-processing function (customize for specific needs)
12
+ def preprocess_text(text):
13
+ # Implement your desired text cleaning or modification logic here
14
+ return text
15
 
16
+ # Function to simulate text input to a text-to-speech API
17
+ def process_text(text):
18
  global voice, speed, pitch
19
 
20
  # Call pre-processing function (if implemented)
21
+ preprocessed_text = preprocess_text(text)
22
 
23
  # Simulate text input to a text-to-speech API (replace with your chosen API)
24
  # This example demonstrates a basic placeholder
25
+ print(f"Simulating text input to TTS API: {preprocessed_text} (Voice: {voice}, Speed: {speed}, Pitch: {pitch})")
26
 
27
  # You'll need to integrate your chosen text-to-speech API here
28
 
29
  # Streamlit App
30
+ st.title("Text-to-Speech Announcer (Headless)")
31
 
32
  # User Interface for customization options
33
  voice_selected = st.selectbox("Voice", ["en", "fr", "es"]) # Add more options
 
39
  speed = speed_slider
40
  pitch = pitch_slider
41
 
42
+ # Button to trigger processing of entered text
43
+ if st.button("Announce Keystroke"):
44
+ if key_input:
45
+ process_text(key_input)
46
+ else:
47
+ st.error("Please enter a keystroke to announce.")
48
 
49
+ st.write("Enter a keystroke in the text box to synthesize speech.")