Added files

This commit is contained in:
ashish committed 2023-09-10 12:31:43 -05:00
1 parent fb69f06561
commit 33429b32af
6 files changed
+85

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
FROM python:3.11
WORKDIR /code
ENTRYPOINT ["python3", "main.py"]
COPY requirements.txt .
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
COPY src .
+2
View File
@@ -0,0 +1,2 @@
pychromecast==13.0.7
gTTS==2.3.2
+38
View File
@@ -0,0 +1,38 @@
from uuid import UUID
import pychromecast
from player import Player
class GoogleHomePlayer(Player):
def __init__(self, friendly_name):
google_home_mini = pychromecast.get_listed_chromecasts(friendly_names=[friendly_name])[0][0]
google_home_mini.wait()
self.media_controller = google_home_mini.media_controller
def play(self, audio_file_url):
if self.media_controller.is_playing:
pass
self.media_controller.play_media(audio_file_url, 'audio/mpeg')
self.media_controller.block_until_active()
def pause(self):
self.media_controller.pause()
def stop(self):
self.media_controller.stop()
if __name__ == '__main__':
google_home_mini = pychromecast.get_listed_chromecasts(friendly_names=['Bedroom speaker'])[0][0]
google_home_mini.wait()
media_controller = google_home_mini.media_controller
media_controller.play_media('http://192.168.0.79:8000/Entertainment%20District%20Soundtrack%20Samuel%20Kim.mp3', 'audio/mpeg')
media_controller.block_until_active()
print(dir(media_controller))
print(media_controller.status)
print(f'is_active: {media_controller.is_active}')
print(f'is_playing: {media_controller.is_playing}')
print(f'is_paused: {media_controller.is_paused}')
print(f'is_idle: {media_controller.is_idle}')
+6
View File
@@ -0,0 +1,6 @@
from google_home_player import GoogleHomePlayer
google_home_mini = GoogleHomePlayer(friendly_name='Bedroom speaker')
google_home_mini.play_message('Good morning, Ashish. Today is Thursday, August 31st . The time is currently 10:00am.')
print(google_home_mini.media_controller.is_playing)
print(google_home_mini.media_controller.is_active)
+26
View File
@@ -0,0 +1,26 @@
from abc import ABC, abstractmethod
from gtts import gTTS
class Player(ABC):
@abstractmethod
def __init__(self, local_ip):
self.local_ip = local_ip
@abstractmethod
def play(self, audio_file_url):
pass
@abstractmethod
def pause(self):
pass
@abstractmethod
def stop(self):
pass
def play_message(self, message):
gTTS(text=message, lang='en').save('/mnt/audio/message.mp3')
self.play('http://192.168.0.79:8000/message.mp3')
#self.play(f'{self.local_ip}/message.mp3')