Speech-Listener 0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ # MANIFEST.in
2
+
3
+ include speech_listener/web/index.html
4
+ include speech_listener/web/script.js
5
+ include speech_listener/web/style.css
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: Speech_Listener
3
+ Version: 0.1
4
+ Summary: A speech recognition listener using Selenium and Web Speech API
5
+ Requires-Dist: selenium
6
+ Requires-Dist: webdriver_manager
7
+ Dynamic: requires-dist
8
+ Dynamic: summary
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html lang="eng">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=divice-width, initial-sclae=1.0" >
6
+ <title>SpeechToText</title>
7
+ <link rel="stylesheet" href="style.css">
8
+ </head>
9
+ <body>
10
+ <h1>SpeechToText</h1>
11
+ <button id="startButton">Start listening</button>
12
+ <div id="output"></div>
13
+ <script src="script.js"></script>
14
+ </body>
15
+ </html>
@@ -0,0 +1,34 @@
1
+ const output = document.getElementById("output");
2
+ const startButton = document.getElementById("startButton");
3
+ let finalTranscript = "";
4
+
5
+ const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition
6
+
7
+ const recognition = new SpeechRecognition();
8
+ recognition.lang = "en-US";
9
+ recognition.interimResults = true;
10
+ startButton.addEventListener("click", () => {
11
+ finalTranscript = '';
12
+ output.textContent = '';
13
+ recognition.start();
14
+ startButton.textContent = "Listening";
15
+ });
16
+
17
+ recognition.addEventListener("result", (e) => {
18
+ const transcript = Array.from(e.results).map(result => result[0].transcript).join("");
19
+ if(e.results[0].isFinal){
20
+ finalTranscript = transcript;
21
+ output.textContent = finalTranscript;
22
+ }
23
+ });
24
+
25
+ recognition.addEventListener("end", () => {
26
+ startButton.textContent = 'Start Listening';
27
+ recognition.start();
28
+ });
29
+ document.addEventListener('keydown', (e) => {
30
+ if(e.key == 'Escape'){
31
+ recognition.stop();
32
+ startButton.textContent = 'Start Listening';
33
+ }
34
+ })
@@ -0,0 +1,10 @@
1
+ body{
2
+ font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
3
+ text-align: center;
4
+ }
5
+ #output{
6
+ margin-top: 20px;
7
+ padding: 10px;
8
+ border: 1px solid;
9
+ min-height: 100px;
10
+ }
@@ -0,0 +1,2 @@
1
+ # Here, . in (.main) means look in the same package folder (i.e. Speech_Listener)
2
+ from .main import listen # exposes listen function globally
@@ -0,0 +1,54 @@
1
+ from selenium import webdriver
2
+ from selenium.webdriver.common.by import By
3
+ from selenium.webdriver.support.ui import WebDriverWait
4
+ from selenium.webdriver.support import expected_conditions as EC
5
+ from selenium.webdriver.chrome.service import Service
6
+ from webdriver_manager.chrome import ChromeDriverManager
7
+ import os
8
+
9
+ # from selenium.webdriver.chrome.options import Options
10
+
11
+ BASE_dir = os.path.dirname(os.path.abspath(__file__))
12
+
13
+ chrome_options = webdriver.ChromeOptions()
14
+ # driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options = chrome_options)
15
+ # driver.get("https://www.youtube.com")
16
+
17
+ # it allows auto access of Microphone to Chrome
18
+ chrome_options.add_argument("--use-fake-ui-for-media-stream")
19
+ chrome_options.add_argument("--headless=new")
20
+
21
+ driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options = chrome_options)
22
+
23
+ website = os.path.join(BASE_dir, "web", "index.html")
24
+ driver.get(f"file:///{website}")
25
+
26
+ rec_file = os.path.join(BASE_dir, "input.txt")
27
+
28
+ def listen():
29
+ try:
30
+ start_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "startButton")))
31
+ start_button.click()
32
+ print('Listening ...')
33
+ output_text = ""
34
+ is_second_click = False
35
+ while True:
36
+ output_element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "output")))
37
+ current_text = output_element.text.strip()
38
+
39
+ if "Start Listening" in start_button.text and current_text != output_text:
40
+ output_text = current_text
41
+ try:
42
+ with open(rec_file, "w") as file:
43
+ file.write(current_text.lower())
44
+ # print('\r', end='', flush=True)
45
+ print(f"Divyanshu : {current_text}")
46
+ except Exception as e:
47
+ print(f'File write error : {e}')
48
+
49
+ except KeyboardInterrupt:
50
+ print('Stopping ....') # Pressed Ctrl + C
51
+ except Exception as e:
52
+ print(f"Error : {e}")
53
+
54
+ listen()
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: Speech_Listener
3
+ Version: 0.1
4
+ Summary: A speech recognition listener using Selenium and Web Speech API
5
+ Requires-Dist: selenium
6
+ Requires-Dist: webdriver_manager
7
+ Dynamic: requires-dist
8
+ Dynamic: summary
@@ -0,0 +1,12 @@
1
+ MANIFEST.in
2
+ setup.py
3
+ Speech_Listener/__init__.py
4
+ Speech_Listener/main.py
5
+ Speech_Listener.egg-info/PKG-INFO
6
+ Speech_Listener.egg-info/SOURCES.txt
7
+ Speech_Listener.egg-info/dependency_links.txt
8
+ Speech_Listener.egg-info/requires.txt
9
+ Speech_Listener.egg-info/top_level.txt
10
+ Speech_Listener/Web_folder/index.html
11
+ Speech_Listener/Web_folder/script.js
12
+ Speech_Listener/Web_folder/style.css
@@ -0,0 +1,2 @@
1
+ selenium
2
+ webdriver_manager
@@ -0,0 +1 @@
1
+ Speech_Listener
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,14 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="Speech_Listener", # name of the Package
5
+ version="0.1",
6
+ description="A speech recognition listener using Selenium and Web Speech API",
7
+ packages = find_packages(),
8
+ package_data={"Speech_Listener" : ["Web_folder/*"]}, # include all files from Web_folder
9
+ include_package_data=True, # works together with MANIFEST.in
10
+ install_requires=[ # your dependencies (auto-installs for users)
11
+ "selenium",
12
+ "webdriver_manager"
13
+ ]
14
+ )