播放音乐时的Python SpeechRecognition



我的程序正在播放音乐,但我想使用SpeechRecognition模块停止它。问题是,模块也在听音乐。有没有办法从SpeechRecognition中删除音乐?

代码:

#!Imports
#!speechRecognition
r = sr.Recognizer()
#!Variables
result = None
currentTime = 0
window = None
#!listenInBackground
#!controllTime
def controllTime():
global currentTime
global window
#~checkforTime
if currentTime != 0:
time.sleep(1)
currentTime = currentTime-1
print(currentTime)
controllTime()
else:
os.system("taskkill /f /im "+"chrome.exe")

#!Videosearch
def searchMusic(s):
global result 
global currentTime
global window
#~GetLink
url = "https://www.youtube.com/results?search_query="+str(s).replace(" ", "")
html = urllib.request.urlopen(url)
video_ids = re.findall(r"watch?v=(S{11})", html.read().decode())
result = "https://www.youtube.com/watch?v="+video_ids[0]
#~getElements
video = pafy.new(result)
currentTime = video.length
#~openWebsite
window = webbrowser.open(result)
#~StartCounters
Thread(target = controllTime).start()
searchMusic("The End")

不,我认为你不能,因为麦克风无法将音乐与你的声音分离(因为它会记录它听到的一切(

最新更新