deblockt / google-home-push

python lib to push message on google case device
MIT License
15 stars 8 forks source link

"say" seems to not work anymore #8

Open dayer4b opened 3 years ago

dayer4b commented 3 years ago

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.

dray-cyber commented 3 years ago

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

dray-cyber commented 3 years ago

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 commented 3 years ago
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 commented 3 years ago

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

dray-cyber commented 3 years ago

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

dray-cyber commented 3 years ago

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!

dayer4b commented 3 years ago

thanks i'll try it!

dayer4b commented 3 years ago

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.

dray-cyber commented 3 years ago

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

dray-cyber commented 3 years ago

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

dray-cyber commented 3 years ago

also some speed for the audio

dray-cyber commented 3 years ago

check my fork/pull request if you care

dayer4b commented 3 years ago

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
dray-cyber commented 3 years ago

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!
peterd550 commented 3 years ago

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

peterd550 commented 3 years ago

This did not work for me

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

dray-cyber commented 3 years ago

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

peterd550 commented 3 years ago

Thanks I have it installed I'm using docker

Do you have this as a pip install?

dray-cyber commented 3 years ago

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 commented 3 years ago

pypi*

dray-cyber commented 3 years ago

alr done do pip install googlecontroller in the future

peterd550 commented 3 years ago

Thanks will try it out 😄

peterd550 commented 3 years ago

Thanks Works well