Giter VIP home page Giter VIP logo

google-home-notifier-python's Introduction

A notification server that sends notifications to Google Home

This is pretty simple. I had started using noelportugal's really great node Google Home Notifier but was having some issues with stability.

I decided to write it in a language i know a bit better - python! yay. Python is your friend.

The gist is this:

This is a webservice that has two endpoints:

  • /play/ - plays an mp3 on the google home that is in the static folder
  • /say/ - uses googles unofficial google translate TTS service to say a notification

use

getting started

This uses flask and you should just be able to install the requirements: pip install -r requirements.txt and then run the webservice python main.py

You will have to edit main.py and change the chromecast_name to one of your google home device's name. If you have more than 1 google home, I would recommend you put all your google homes into a play group and place the play groups name in the device_name variable.

URLs

/play/mp3name.mp3

This will play mp3name.mp3 over the google homes. I put two mp3s in the static dir for you to try out: JR.mp3 and doorbell1.mp3. Try them: /play/JR.mp3 or /play/doorbell1.mp3

/say/?text=Oh My God this is awesome

Just pass a GET variable to the /say/ endpoint and the google homes will say your text. It also caches this so that the second time it will be a bit quicker than the first time. yay.

You can also do other languages too:

/say/?text=猿も木から落ちる&lang=ja

running for real

I use docker to run it. It works pretty well. I even included some pretty good docker script that will make it easier. Please check that out for more help.

How

Google homes are just chromecasts! Who knew! You just have to treat them like chromecasts. They show up when you browse for chromecasts via python or any other code library. You can then just send audio their way.

TODO

  • Break out the google home bits and make it easy to integrate into other projects and not just a webservice

HMU

[email protected]

@harper on twitter

google-home-notifier-python's People

Contributors

amazingfly avatar harperreed avatar jmndoza avatar tobycourtis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google-home-notifier-python's Issues

No audio from speaker

Everything seems to be working for me except the audio file doesn't actually play through my speaker.

  • I can tell that it is successfully connecting to the speaker as it interrupts music and sometimes plays the 'cast ding sound'
  • the audio files, which are generated from text, play correctly on my computer
  • I have tried using different speakers but each had the same result

Can't figure out what is going wrong.

commands not working

say command is not working at all
when i use the "say" command my google home just make a sound and then nothing

AttributeError: 'Chromecast' object has no attribute 'cast_info'

Problem

When try to launch main.py, it causes AttributeError: 'Chromecast' object has no attribute 'cast_info'

Actual

Startup fails.

INFO:root:Starting up chromecasts
INFO:pychromecast:Querying device status
INFO:root:Searching for ghm
Traceback (most recent call last):
  File "/home/gh-notifier/google-home-notifier-python/main.py", line 19, in <module>
    cast = next(cc for cc in chromecasts if cc.cast_info.friendly_name == chromecast_name)
  File "/home/gh-notifier/google-home-notifier-python/main.py", line 19, in <genexpr>
    cast = next(cc for cc in chromecasts if cc.cast_info.friendly_name == chromecast_name)
AttributeError: 'Chromecast' object has no attribute 'cast_info'

Expected

python main.py launches successfully.

Additional information

I'm using it with Google Home Mini.

$ pip list
Package            Version
------------------ ---------
casttube           0.2.1
certifi            2021.5.30
charset-normalizer 2.0.4
click              8.0.1
Flask              2.0.1
gTTS               2.2.3
idna               3.2
ifaddr             0.1.7
itsdangerous       2.0.1
Jinja2             3.0.1
MarkupSafe         2.0.1
pathlib            1.0.1
pip                21.1.3
protobuf           3.17.3
PyChromecast       9.2.0
requests           2.26.0
setuptools         56.0.0
six                1.16.0
unicode-slugify    0.1.3
Unidecode          1.2.0
urllib3            1.26.6
Werkzeug           2.0.1
zeroconf           0.36.0
WARNING: You are using pip version 21.1.3; however, version 22.0.4 is available

With debugging, it seems there is a case that cast_info property can not be accessible.

>>> print(chromecasts)
[Chromecast(None, port=8009, device=DeviceStatus(friendly_name='ghm', model_name='Google Home Mini', manufacturer='Google Inc.', uuid=UUID('...'), cast_type='audio'))]
>>> cast = chromecasts[0]
>>> cast
Chromecast(None, port=8009, device=DeviceStatus(friendly_name='ghm', model_name='Google Home Mini', manufacturer='Google Inc.', uuid=UUID('...'), cast_type='audio'))

cast. doesn't show cast_info.

>>> cast.
cast.app_display_name                 cast.model_name                       cast.socket_client
cast.app_id                           cast.name                             cast.start(
cast.cast_type                        cast.new_cast_status(                 cast.start_app(
cast.connect(                         cast.play_media(                      cast.status
cast.device                           cast.quit_app(                        cast.status_event
cast.disconnect(                      cast.register_connection_listener(    cast.uri
cast.ignore_cec                       cast.register_handler(                cast.uuid
cast.is_idle                          cast.register_launch_error_listener(  cast.volume_down(
cast.join(                            cast.register_status_listener(        cast.volume_up(
cast.logger                           cast.set_volume(                      cast.wait(
cast.media_controller                 cast.set_volume_muted(                

I've used cast.name as a workaround.

$ git diff
diff --git a/main.py b/main.py
index 3fde0a2..2e55441 100644
--- a/main.py
+++ b/main.py
@@ -16,7 +16,7 @@ app = Flask(__name__)
 logging.info("Starting up chromecasts")
 chromecasts, _ = pychromecast.get_chromecasts()
 logging.info("Searching for {}".format(chromecast_name))
-cast = next(cc for cc in chromecasts if cc.cast_info.friendly_name == chromecast_name)
+cast = next(cc for cc in chromecasts if cc.name == chromecast_name)
 
 def play_tts(text, lang='en', slow=False):
     tts = gTTS(text=text, lang=lang, slow=slow)

Google Cast Error

Hi. How to access Google home IP address remotely when I'm outside of local wifi network?

It is not an issue.

Thanks Harper for Obama... and the interface.
The main.py runs ok no errors but I am not getting a sound from the Google Home. Except the first time when lounching app CC1AD845 I can hear the short "ploom".
My log:
ARNING:werkzeug: * Debugger is active!
INFO:werkzeug: * Debugger PIN: 318-290-727
INFO:root:http://eee:5000/static/cache/co-tam-sie-dzieje-pl-false.mp3
http://eee:5000/static/cache/co-tam-sie-dzieje-pl-false.mp3
INFO:pychromecast.controllers:Receiver:Launching app CC1AD845
INFO:werkzeug:192.168.90.2 - - [13/Oct/2017 15:26:09] "GET /say/?text=%22co%20tam%20sie%20dzieje%22&lang=pl HTTP/1.1" 200 -
INFO:root:http://eee:5000/static/cache/co-tam-sie-dzieje-pl-false.mp3
http://eee:5000/static/cache/co-tam-sie-dzieje-pl-false.mp3
INFO:pychromecast.controllers:Not launching app CC1AD845 - already running
INFO:werkzeug:192.168.90.2 - - [13/Oct/2017 15:26:22] "GET /say/?text=%22co%20tam%20sie%20dzieje%22&lang=pl HTTP/1.1" 200 -
Play mp3 behaves the same.

StopIteration Error - docker-compose up

I get the following error after running docker-compose up :

Attaching to home-notifier
home-notifier  | INFO:root:Starting up chromecasts
home-notifier  | INFO:root:Searching for None
home-notifier  | Traceback (most recent call last):
home-notifier  |   File "main.py", line 19, in <module>
home-notifier  |     cast = next(cc for cc in chromecasts if cc.device.friendly_name == chromecast_name)
home-notifier  | StopIteration
home-notifier exited with code 1

I changed GRP_NAME in Dockerfile to the device name. I have only one Google Device.

Error?

Getting the following error on my Raspberry PI after following instructions on installing, any ideas?

Traceback (most recent call last):
File "main.py", line 3, in
import pychromecast
File "/usr/local/lib/python2.7/dist-packages/pychromecast/init.py", line 15, in
from .discovery import discover_chromecasts, start_discovery, stop_discovery
File "/usr/local/lib/python2.7/dist-packages/pychromecast/discovery.py", line 5, in
from zeroconf import ServiceBrowser, Zeroconf
File "/usr/local/lib/python2.7/dist-packages/zeroconf.py", line 175
def current_time_millis() -> float:
^
SyntaxError: invalid syntax

Start at Boot

Hello,

Really good job :-)

But how i can launch the script at boot on raspberry pi, I've tried many time but i've got error:
Traceback (most recent call last):
File "/home/pi/Desktop/google-home-notifier-python/main.py", line 3, in
import pychromecast
ImportError: No module named pychromecast

If i launch the script via the command line it's work like a charme.

Thanks

Docker is mandatory?

This is not an issue more a question:
Can we just run the notifier webservice over Apache. I already have a full home automation solution that already runs an Apache web server.
Please give us a way to integrate on existing web servers.
Thanks

play_mp3 plays too fast or not at all

I'm using on Windows 10 with Python 3.6.8 and a Google Home Mini. Using your main.py and can connect to my mini but when using play_mp3("doorbell1.mp3") it either plays very fast, like 4 or 5 rings in just a second or not at all, works about 1 time out of 5 to 10 tries. What can I do so it plays at the correct speed and consistently works?

I can't use play("doorbell1.mp3") since I get the errors:
RuntimeError: Working outside of request context.
This typically means that you attempted to use functionality that needed an active HTTP request

Thanks - Gary

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.