-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.py
48 lines (40 loc) · 1.47 KB
/
game.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
import speech
import subprocess as sp
from player import Player
from typing import Optional
import sys
import main
import random
class Game:
def __init__(self) -> None:
self.speechRecognizer = speech.Speech(2)
self.player_left = self.init_player("left")
self.player_right = self.init_player("right")
# self.playlist = self.init_playlist()
# self.spotify = Spotify()
def init_player(self, player_side: str) -> Optional[Player]:
say(f"Player on the {player_side} side, what is your name?")
player = Player(self.speechRecognizer.startSpeechRecognition(5))
false_counter = 0
while false_counter < 3 and\
(player.name == '' or player.name.count(' ') + 1 > 2):
print(f'Error in given name {player.name}')
say("Sorry, I didn't quite catch that, can you repeat?")
player = Player(self.speechRecognizer.startSpeechRecognition(5))
false_counter += 1
if false_counter > 3:
say("This doesn't seem to be working, please try again later.")
sys.exit()
print(player.name)
say(f'nice to meet you {player.name}!')
return player
def say(text: str) -> None:
sp.call(['say', text])
if __name__ == '__main__':
spotify = main.setup()
game = Game()
main.run(spotify)
# FOR JOSH COPY PASTE:
# self.speechRecognizer.startSpeechRecognition(5)
# def say(text: str) -> None:
# sp.call(['say', text])