Re: [python] TTS et chromecast
Publié : 07 mai 2017, 13:35
Ok, mon zidoo est un X6 Pro, il n'a pas d'afficheur, juste une led bleue de fonctionnement.
Reprenez le contrôle de votre domotique
https://easydomoticz.com/forum/
explique moi ta demarche en mp stp (comment tu fais que j'essaye de reproduire), pour ceux qui ont une freebox revolution le serveur a deux hp de crotte c'est vrai mais suffisant pour faire de la notification vocal et sonore, on y accede par de l'upnp dlna.frenchyyii a écrit :Salut, peut-on caster sur autre chose qu'une chrome cast ? Genre sur ma freebox .
Avec mon zidoo j'arrive à caster le son de google now et de mon zidoo "par dessus ce que je regarde
/ecoute à la tv" et franchement j'aime bien.
Et sur une enceinte BT on peut aussi l'adapter ?
Merci
Code : Tout sélectionner
tkk_expr = re.search(".*?(TKK=.*?;)W.*?", line).group(1)
a = re.search("a\\\\x3d(-?\d+);", tkk_expr).group(1)
b = re.search("b\\\\x3d(-?\d+);", tkk_expr).group(1)
result = str(hours) + "." + str(int(a) + int(b))Code : Tout sélectionner
result = re.search("TKK='(.+?)';", line).group(1)Code : Tout sélectionner
#!/usr/bin/python3
from __future__ import print_function
import sys; sys.path.insert(0,'/usr/local/lib/python3.4/dist-packages/')
import time
import pychromecast
import re
from gtts import gTTS
State = {}
def store_state(cast, volume):
print('save state')
State.clear()
if (cast.status != None):
State['Volume'] = cast.status.volume_level
State['Muted'] = cast.status.volume_muted
cast.set_volume(int(volume) / 100)
cast.set_volume_muted(False)
def restore_state(self):
if (State['Volume'] != None):
if 'Volume' in State: cast.set_volume(State['Volume'])
if 'Muted' in State: cast.set_volume_muted(State['Muted'])
print('restore state')
regex = re.compile(
r'^(?:http|ftp)s?://' # http:// or https://
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
r'localhost|' #localhost...
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
r'(?::\d+)?' # optional port
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
arg = sys.argv[1]
volume = sys.argv[2] if 2 < len(sys.argv) else 40
if re.match(regex, arg ) is not None:
url_to_play = arg
else:
URL_DOMOTICZ = 'http://192.168.44.2:8080/'
tts = gTTS(text=arg, lang='fr', slow=True)
tts.save("/usr/share/domoticz/www/notification.mp3")
url_to_play = URL_DOMOTICZ+'notification.mp3'
chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=["Salon"])
cast = chromecasts[0]
cast.wait()
store_state(cast, volume)
mc = cast.media_controller
mc.play_media(url_to_play, 'audio/mp3')
mc.block_until_active()
mc.pause()
mc.play()
endTime = time.time() + 10
while (mc.status.player_is_idle) and (time.time() < endTime):
print("Waiting for player (timeout in "+str(endTime - time.time())[:4]+" seconds)")
time.sleep(0.5)
if (mc.status.duration != None):
endTime = time.time()+mc.status.duration+1
while (time.time() < endTime) and (not mc.status.player_is_idle):
if (mc.status.duration != None):
print("Waiting for message to complete playing ("+str(mc.status.adjusted_current_time)[:4]+" of "+str(mc.status.duration)+", timeout in "+str(endTime - time.time())[:4]+" seconds)")
else:
print("Waiting for message to complete playing (unknown duration, timeout in "+str(endTime - time.time())[:4]+" seconds)")
time.sleep(0.5)
restore_state(cast)