google-home-push icon indicating copy to clipboard operation
google-home-push copied to clipboard

"say" seems to not work anymore

Open dayer4b opened this issue 4 years ago • 23 comments

I haven't had a chance to test other features of this library, but "say" seems to no longer work. I believe it may be due to the API changes around gTTS. It seems like gTTS-token is now deprecated and the functionality is no longer necessary.

https://github.com/Boudewijn26/gTTS-token/blob/master/docs/november-2020-translate-changes.md

This suggests that libraries that are using this need to be updated to follow the new method.

dayer4b avatar Dec 01 '20 15:12 dayer4b

I have found a way to fix that let me submit a change request.

dray-cyber avatar Dec 01 '20 19:12 dray-cyber

I have no honest clue on how to do this so Im going to paste the new code here for the file init.py

dray-cyber avatar Dec 01 '20 19:12 dray-cyber

import pychromecast

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):
        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.')

    def say(self, text, lang = 'en-US'):
        url = u"https://translate.google.com/translate_tts?ie=UTF-8&q=" + text + "%21&tl=" + lang + "&ttsspeed=1&total=1&idx=0&client=tw-ob&textlen=14&tk=594228.1040269"
        self.play(url)

    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)

dray-cyber avatar Dec 01 '20 19:12 dray-cyber

This may not be the best way to rewrite the tts script but it works very well for me atleast.

dray-cyber avatar Dec 01 '20 20:12 dray-cyber

Anyways Its locked to English I am going to go write a fix for that right now.

dray-cyber avatar Dec 01 '20 20:12 dray-cyber

Alright wrote a fix edited the last comment accordingly.Side note this renders the rest of the tts files worthless.Let me know if this helps!

dray-cyber avatar Dec 01 '20 20:12 dray-cyber

thanks i'll try it!

dayer4b avatar Dec 01 '20 20:12 dayer4b

btw, to make a pull request in Github, it's probably simplest for you to follow the Forking Workflow. To do that, fork the repo and then commit the changes to your version. You can then create a Pull Request on this repo from your fork.

dayer4b avatar Dec 01 '20 20:12 dayer4b

I figured it out a while ago thanks though! Works right?

dray-cyber avatar Dec 01 '20 22:12 dray-cyber

Also I figured out some more code to enable it to accept audio controls.

dray-cyber avatar Dec 01 '20 22:12 dray-cyber

also some speed for the audio

dray-cyber avatar Dec 01 '20 22:12 dray-cyber

check my fork/pull request if you care

dray-cyber avatar Dec 01 '20 22:12 dray-cyber

your fork worked great! I switched to your library. FYI, in your README.md you mention that pip install doesn't work yet. You may not have your package on PyPi, but you can still pip install from git sources. Example:

pip install git+https://github.com/dray-cyber/googlehomepush-v2@a35d948ae8d253a58dedc9df94abb8fb680e0e80

dayer4b avatar Dec 02 '20 14:12 dayer4b

your fork worked great! I switched to your library. FYI, in your README.md you mention that pip install doesn't work yet. You may not have your package on PyPi, but you can still pip install from git sources. Example:

pip install git+https://github.com/dray-cyber/googlehomepush-v2@a35d948ae8d253a58dedc9df94abb8fb680e0e80

Thats absolutely awesome I forgot about that thank you!

dray-cyber avatar Dec 02 '20 14:12 dray-cyber

Can you not merge the code to master ? Can you then update your python page?

peterd550 avatar Dec 15 '20 09:12 peterd550

This did not work for me

pip install git+https://github.com/dray-cyber/googlehomepush-v2@a35d948ae8d253a58dedc9df94abb8fb680e0e80

peterd550 avatar Dec 17 '20 08:12 peterd550

This did not work for me

pip install git+https://github.com/dray-cyber/googlehomepush-v2@a35d948ae8d253a58dedc9df94abb8fb680e0e80

i believe you need git installed but I may be wrong anyways I also have a new google controller package that you can copy and paste in the sitepackages folder of python

dray-cyber avatar Dec 25 '20 02:12 dray-cyber

Thanks I have it installed I'm using docker

Do you have this as a pip install?

peterd550 avatar Dec 25 '20 05:12 peterd550

Thanks I have it installed I'm using docker

Do you have this as a pip install?

Not yet Im working on uploading this to pypy

dray-cyber avatar Dec 25 '20 16:12 dray-cyber

pypi*

dray-cyber avatar Dec 25 '20 16:12 dray-cyber

alr done do pip install googlecontroller in the future

dray-cyber avatar Dec 25 '20 17:12 dray-cyber

Thanks will try it out 😄

peterd550 avatar Dec 26 '20 01:12 peterd550

Thanks Works well

peterd550 avatar Dec 27 '20 00:12 peterd550