Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it work! #10

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
62 changes: 2 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,2 @@
[![PyPI version](https://badge.fury.io/py/googlehomepush.svg)](https://badge.fury.io/py/googlehomepush)

# Google home push

Library for Python 3.4+ to push text message or audio file with the Google Home.

## Installation

pip install googlehomepush

## Dependencies

PyChromecast depends on the Python packages gTTS, pychromecast. Make sure you have these dependencies installed using `pip install -r requirements.txt`

## How to use

``` python
from googlehomepush import GoogleHome

GoogleHome("LivingRoom").say("test")
GoogleHome("LivingRoom").play("http://www.hubharp.com/web_sound/BachGavotteShort.mp3")
```

## API

### GoogleHome(devicename = None, host = None, port = None, tts_builder = googleTTS_Builder)

Create a new Google Home `instance` (a device name or host is mandatory).
- `devicename` can be the google home name, or its IP (local).
- `host` an ip of a Google Home
- `port` port used to connect Google Home
- `tts_builder` the tss engine to use. Available tts are:
- `googleTTS_Builder` import with `from googlehomepush.googletts import googleTTS_builder`. Free TTS used by google translate. It's the default engine
- `googlecloudTTS_builder` import with `from googlehomepush.googlecloudTTS import googlecloudTTS_builder`. Google cloud TTS engine. See https://cloud.google.com/text-to-speech/docs/reference/libraries to create an account.

### .say(text, lang = 'en-US')

Push a message on Google home

- `text` is the test message to say
- `lang` the text language, default value is 'en'

### .play(url, contentType = 'audio/mp3'):

Push a sond to Google home
- `url` an audio file URL
- `contentType` the audi file content type

You can play a local file using `http_server`

``` python
from googlehomepush.http_server import serve_file

file_url = serve_file("/path/to/file", "audio/mp3")
GoogleHome("LivingRoom").play(file_url, "audio/mp3")
```

## Maintainers

- Thomas Deblock (@tdeblock)
This is outdated switch to google controller one of my other repos, far more advanced then this.
Use this one https://github.com/dray-cyber/googlecontroller
54 changes: 17 additions & 37 deletions googlehomepush/__init__.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,23 @@
import pychromecast
from .googletts import googleTTS_builder

name = "googlehomepush"
__all__ = (
'GoogleHome',
)

class GoogleHome:
"""
Create a Google home (an host or a devicename is mandatory)
:param devicename: string : the ip or device name of the Google Home
:param host: the host of google home
:param port: the port to contact google home by ip (default is 8009)
:param ttsbuilder: function: the tts function. This is a function who have two parameter a text string and the lang. This function return an url to download mp3 file
"""
def __init__(self, devicename = None, host = None, port = None, ttsbuilder = googleTTS_builder):
if devicename != None:
chromecasts = pychromecast.get_chromecasts()
filteredChromeCast = filter(lambda c: c.host == devicename or c.device.friendly_name == devicename , chromecasts)

try:
self.cc = next(filteredChromeCast)
except StopIteration:
availbale_devices = list(map(lambda c: c.device.friendly_name, chromecasts))
raise ValueError('Unable to found %s device. Available devices : %s'%(devicename, availbale_devices))
elif host != None:
self.cc = pychromecast.Chromecast(host, port)
else:
raise ValueError('host or devicename is mandatory to create a GoogleHome object.')

self.ttsbuilder = ttsbuilder

def say(self, text, lang = 'en-US'):
ttsurl = self.ttsbuilder(text, lang)
self.play(ttsurl)

name = "googlecontroller"
__all__ = 'GoogleAssistant'
class GoogleAssistant:
def __init__(self, host = None):
try:
if host != None:
self.cc = pychromecast.Chromecast(host)
else:
print('For a host input the ip and have the option like: host = "192.168.0.whatever" home = GoogleHome(host=host) ')
except:
print("Some sort of error occured")
def play(self, url, contenttype = 'audio/mp3'):
self.cc.wait()
mc = self.cc.media_controller
mc.play_media(url, contenttype)
mc.block_until_active()
print("played url " + url)
def say(self, text, speed = 1, lang = 'en-US'):
speed = str(speed)
url = u"https://translate.google.com/translate_tts?ie=UTF-8&q=" + text + "%21&tl=" + lang + "&ttsspeed=" + speed + "&total=1&idx=0&client=tw-ob&textlen=14&tk=594228.1040269"
self.play(url)
def volume(self, volumelevel):
self.cc.set_volume(volumelevel)
26 changes: 0 additions & 26 deletions googlehomepush/googlecloudTTS.py

This file was deleted.

141 changes: 0 additions & 141 deletions googlehomepush/googletts.py

This file was deleted.