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.
- speech_listener-0.1/MANIFEST.in +5 -0
- speech_listener-0.1/PKG-INFO +8 -0
- speech_listener-0.1/Speech_Listener/Web_folder/index.html +15 -0
- speech_listener-0.1/Speech_Listener/Web_folder/script.js +34 -0
- speech_listener-0.1/Speech_Listener/Web_folder/style.css +10 -0
- speech_listener-0.1/Speech_Listener/__init__.py +2 -0
- speech_listener-0.1/Speech_Listener/main.py +54 -0
- speech_listener-0.1/Speech_Listener.egg-info/PKG-INFO +8 -0
- speech_listener-0.1/Speech_Listener.egg-info/SOURCES.txt +12 -0
- speech_listener-0.1/Speech_Listener.egg-info/dependency_links.txt +1 -0
- speech_listener-0.1/Speech_Listener.egg-info/requires.txt +2 -0
- speech_listener-0.1/Speech_Listener.egg-info/top_level.txt +1 -0
- speech_listener-0.1/setup.cfg +4 -0
- speech_listener-0.1/setup.py +14 -0
|
@@ -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,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,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 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Speech_Listener
|
|
@@ -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
|
+
)
|