-
Notifications
You must be signed in to change notification settings - Fork 0
/
Speech.py
81 lines (69 loc) · 2.02 KB
/
Speech.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: Geekman2
#
# Created: 22/11/2014
# Copyright: (c) Geekman2 2014
# Licence: <your licence>
#-------------------------------------------------------------------------------
from dragonfly.all import CompoundRule, Grammar, Key
import win32com.client
import win32gui
import natlink
import time
import vlc
import os
import random
musdir = r"C:/Users/Geekman2/Dropbox/Tessa and Devon/__Devon/"
wmp = win32com.client.dynamic.Dispatch("WMPlayer.OCX")
wmp.settings.autoStart = True
wmp.settings.volume = 50
playlist = os.listdir(musdir)
def addSong(file):
wmp.URL = file
while wmp.Playstate != 1:
win32gui.PumpWaitingMessages()
time.sleep(0.1)
class ExampleRule(CompoundRule):
spec = "car"
def _process_recognition(self,node,extras):
print "Voice command spoken"
class PlayMusicRule(CompoundRule):
spec = "Music Time"
def _process_recognition(self,node,extras):
song = random.choice(playlist)
print song
addSong(musdir+song)
class SkipRule(CompoundRule):
spec = "Skip"
def _process_recognition(self,node,extras):
song = random.choice(playlist)
print song
addSong(musdir+song)
class StopRule(CompoundRule):
spec = "Pause"
def _process_recognition(self,node,extras):
player.pause()
class ResumeRule(CompoundRule):
spec = "Resume"
def _process_recognition(self,node,extras):
player.play()
class VolumeUp(CompoundRule):
spec = "Volume Up"
def _process_recognition(self,node,extras):
a1 = Key("w-b,right,right,right,right,enter,up:20")
a1.execute()
grammar = Grammar("Basic Grammar")
grammar.add_rule(PlayMusicRule())
grammar.add_rule(SkipRule())
grammar.add_rule(StopRule())
grammar.add_rule(ResumeRule())
grammar.add_rule(VolumeUp())
natlink.natConnect()
grammar.load()
print natlink.getMicState()
grammar.enable()
natlink.waitForSpeech()
natlink.natDisconnect()