Skip to content

Instantly share code, notes, and snippets.

@KaushikShresth07
Created March 31, 2024 10:21
Show Gist options
  • Select an option

  • Save KaushikShresth07/6cbeb81516bf561d7ee5e82e208e071b to your computer and use it in GitHub Desktop.

Select an option

Save KaushikShresth07/6cbeb81516bf561d7ee5e82e208e071b to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Speech Recognition</title>
</head>
<body>
<button id = "start" onclick="startRecognition()">Start Recognition</button>
<button id = "end" onclick="stopRecognition()">Stop Recognition</button>
<p id = "output"></p>
<script>
const output = document.getElementById('output');
let recognition;
function startRecognition() {
recognition = new webkitSpeechRecognition() || new SpeechRecognition();
recognition.lang = 'en-US';
recognition.continuous = true;
recognition.onresult = function(event) {
const transcript = event.results[event.results.length - 1][0].transcript;
output.textContent += transcript;
};
recognition.onend = function() {
recognition.start();
};
recognition.start();
}
function stopRecognition() {
recognition.stop();
output.innerHTML = ""
}
</script>
</body>
</html>
@gourmanmohan23-web

Copy link
Copy Markdown

pip install webdriver_manager

pip install selenium

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

Link = r"C:\Users\mrmil\OneDrive\Desktop\Jarvis4YouTube\voice.html"
chrome_options = Options()
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.142.86 Safari/537.36"
chrome_options.add_argument(f'user-agent={user_agent}')
chrome_options.add_argument("--use-fake-ui-for-media-stream")
chrome_options.add_argument("--use-fake-device-for-media-stream")
chrome_options.add_argument("--headless=new")
service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=chrome_options)
driver.get(Link)

def SpeechRecognitionModel():
driver.find_element(by=By.ID,value="start").click()
print("Listening...")
while True:
try:
Text = driver.find_element(by=By.ID,value="output").text
if Text:
driver.find_element(by=By.ID,value="end").click()
return Text

              else:
                    sleep(0.333)

        except:
              pass

@gourmanmohan23-web

Copy link
Copy Markdown
<script src="https://gist.github.com/KaushikShresth07/6cbeb81516bf561d7ee5e82e208e071b.js"></script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment