-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (74 loc) · 3.67 KB
/
main.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
78
print("Importing time...")
import time
#from pydub import AudioSegment
#from pydub.playback import play
print("Importing VoiceRecognizer...")
from lib.voice_recognition.speech_recognition_module import VoiceRecognizer, Commands
from lib.voice_recognition.phrases import *
print("Importing SpotifyClient...")
from api.spotify_client import SpotifyClient
#from gtts import gTTS
print("Importing Firebase...")
from firebase.db import send_to_firebase
from firebase.db import send_status
print("Importing OS...")
import os
def main():
print("Initializing VoiceRecognizer...")
voice = VoiceRecognizer()
print("Initializing SpotifyClient...")
spotify = SpotifyClient()
while True:
voice.command = ""
print("Listening...")
voice.recognize_speech()
send_status(voice.text)
if voice.command == Commands.EXIT:
break
elif voice.command == Commands.PLAY:
song = str(voice.text).split(play_phrase[0])[1]
song_uri = spotify.get_track_uri(song)
spotify.play(song_uri)
current_track_info = spotify.get_current_track_info()
send_to_firebase(current_track_info['song'], current_track_info['artist'], current_track_info['album'])
elif voice.command == Commands.PLAY_PLAYLIST_0:
playlist = str(voice.text).split(play_playlist_phrase[0])[1].strip()
print(f"Playing playlist: {playlist}")
playlist_id = spotify.get_playlist_id(playlist)
spotify.play_playlist(playlist_id)
current_track_info = spotify.get_current_track_info()
send_to_firebase(current_track_info['song'], current_track_info['artist'], current_track_info['album'])
elif voice.command == Commands.PLAY_PLAYLIST_1:
playlist = str(voice.text).split(play_playlist_phrase[1])[1].strip()
print(f"Playing playlist: {playlist}")
playlist_id = spotify.get_playlist_id(playlist)
spotify.play_playlist(playlist_id)
current_track_info = spotify.get_current_track_info()
send_to_firebase(current_track_info['song'], current_track_info['artist'], current_track_info['album'])
elif voice.command == Commands.PLAY_PLAYLIST_2:
playlist = str(voice.text).split(play_playlist_phrase[2])[1].strip()
print(f"Playing playlist: {playlist}")
playlist_id = spotify.get_playlist_id(playlist)
spotify.play_playlist(playlist_id)
current_track_info = spotify.get_current_track_info()
send_to_firebase(current_track_info['song'], current_track_info['artist'], current_track_info['album'])
elif voice.command == Commands.PAUSE:
spotify.pause()
elif voice.command == Commands.RESUME:
spotify.resume_playing()
elif voice.command == Commands.PREVIOUS:
spotify.previous_song()
current_track_info = spotify.get_current_track_info()
send_to_firebase(current_track_info['song'], current_track_info['artist'], current_track_info['album'])
elif voice.command == Commands.NEXT:
spotify.skip_song()
current_track_info = spotify.get_current_track_info()
send_to_firebase(current_track_info['song'], current_track_info['artist'], current_track_info['album'])
elif voice.command == Commands.VOLUME_INCREASE: # DOESN'T WORK ON MOBILE
spotify.set_volume(True)
elif voice.command == Commands.VOLUME_DECREASE: # DOESN'T WORK ON MOBILE
spotify.set_volume(False)
#elif voice.command == Commands.UNKNOWN:
#play(AudioSegment.from_mp3("hello.mp3"))
if __name__ == "__main__":
main()