-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpec_audio.py
More file actions
46 lines (37 loc) · 1.43 KB
/
pec_audio.py
File metadata and controls
46 lines (37 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import speech_recognition as sr
import os
import pywhatkit as pwk
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
r = sr.Recognizer()
data = sr.AudioFile('speech.wav')
with data as source:
audio = r.record(source)
text = r.recognize_google(audio, language="en-IN")
print(text)
if "Alexa" in text:
text.replace("Alexa", "")
if "open" in text:
if "Chrome" in text:
os.system("python open.py chrome")
if "play" in text:
print("play in text")
driver = webdriver.Firefox(executable_path="/home/garuda/Github projects/Virtual-assistant/geckodriver")
driver.implicitly_wait(5)
# Let's create a list of terms to search for and an empty list for links
search_terms = [text]
links = []
for term in search_terms:
# Open YouTube page for each search term
driver.get('https://www.youtube.com/results?search_query={}'.format(term))
# Find a first webelement with video thumbnail on the page
link_webelement = driver.find_element(By.CSS_SELECTOR, 'div#contents ytd-item-section-renderer>div#contents a#thumbnail')
# Grab webelement's href, this is your link, and store in a list of links:
links += [link_webelement.get_attribute('href')]
else:
print("no useful commands found")
print(links)
driver.quit()
os.system("google-chrome-stable "+links[0])
print("2 done")