Closed DewGew closed 5 years ago
Repeat after me is a native function already but I cant make this command with mqtt.
I have already pointed out to Sid that this command does not work on mqtt
I just need a function and send custom voice notifications true gassistpi. Should be possible to make a custom function for this.
I created my own function. I added this: in actions.py:
def speak(phrase):
voice_notify = phrase.replace("speak", "")
print(voice_notify)
say(voice_notify)
and in main.py:
from actions import speak
if 'speak'.lower() in str(usrcmd).lower():
self.assistant.stop_conversation()
speak(str(usrcmd).lower())
with this I can send voice notifications with mqtt command:
custom speak I am new to google assistant
and Gassist Pi replies "Im new to google assistant"
Now only thing is that swedish characters not working via mqtt. I can't send å ä and ö.
I only get those like '\xc3\x85', '\xc3\x84', '\xc3\x96'
. Any ideas howto get this to work?
@shivasiddharth
I'm trying with say(voice_notify.decode("utf-8"))
or say(str(voice_notify.decode("utf-8")))
none is working. I also tried with print instead of say. Dont even print out this.
But this works in def on_message():
print("Message from MQTT: "+str(msg.payload.decode("utf-8")))
I get segmentation error when running this in assistant. What might I have done wrong?
@jcksnmdy My code had a typo fault. Test with new code above..
@DewGew Now only thing is that swedish characters not working via mqtt. I can't send å ä and ö. I only get those like '\xc3\x85', '\xc3\x84', '\xc3\x96'. Any ideas howto get this to work?
it is not enough to insert utf-8 in mqtt the problem is in action.py in the "word translator" function is not declared unicode utf-8
def trans(words,destlang,srclang): transword= translator.translate(words, dest=destlang, src=srclang) transword=transword.text transword=transword.replace("Text, ",'',1) transword=transword.strip() print(transword) return transword
@shivasiddharth do you have any suggestions to solve the unicode problem in word translate
Word translate is not the problem even print() does not work. Strange thing is that print("Message from MQTT: "+str(msg.payload.decode("utf-8"))) is working but print(str(mqtt_query.decode("utf-8"))) or print(mqtt_query.decode("utf-8")) does not work
your print is wrong you have to set it up and you'll see that it works: print("Message from MQTT: "+str(msg.payload.decode("utf-8")))
to me it also prints the accents correctly. it is then the translator that goes haywire
the code correct for mqtt is: def on_message(self, client, userdata, msg): if self.can_start_conversation == True: print("Message from MQTT: "+str(msg.payload.decode("utf-8"))) mqtt_query=str(msg.payload)[1:] if 'custom' in mqtt_query.lower(): mqtt_query=mqtt_query.lower() mqtt_queryidx=mqtt_query.find('custom') mqtt_query=mqtt_query[mqtt_queryidx:] mqtt_query=mqtt_query.replace('custom',"",1) mqtt_query=mqtt_query.strip() self.custom_command(mqtt_query) else: self.assistant.send_text_query(mqtt_query)
if I write in Italian custom speak "è vero" the message is printed correctly but pronounced with the errors x Message from MQTT: custom speak è vero \ xc3 \ xa8 vero ' Playing WAVE '/tmp/male-say.wav' : Signed 16 bit Little Endian, Rate 24000 Hz, Mono
Did you guys try adding the UTF-8 encoding at the top of the script ?
yes, don't work
"# -- coding: utf-8 -- "
above this line
https://github.com/shivasiddharth/GassistPi/blob/b737c460f86b80da059df573796514db00212ad7/src/actions.py#L315
add
print(sayword)
And above this line
https://github.com/shivasiddharth/GassistPi/blob/b737c460f86b80da059df573796514db00212ad7/src/actions.py#L307
add
print(words)
Now give the command and post as to what those lines are printing.
Message from MQTT: custom speak è vero \xc3\xa8 vero ' \ xc3 \ xa8 vero ' \ xc3 \ xa8 vero ' Playing WAVE '/tmp/male-say.wav' : Signed 16 bit Little Endian, Rate 24000 Hz, Mono
After this line
https://github.com/shivasiddharth/GassistPi/blob/b737c460f86b80da059df573796514db00212ad7/src/main.py#L453
add mqtt_query = mqtt_query.decode("utf-8")
adding that line hangs and writes: Message from MQTT: <built-in method decode of bytes object at 0x6f43bc68>
mqtt does his job well and prints the accents correctly. the problem is something else
print ("Messaggio da MQTT:" + str (msg.payload.decode ("utf-8") ))
Guess you have added it at wrong place. Adding mqtt_query = mqtt_query.decode("utf-8")
after mqtt_query=str(msg.payload)[1:]
will not affect the print("Message from MQTT: "+str(msg.payload.decode("utf-8")))
great work, thanks for solving @shivasiddharth
This does not work for me.. If I ask what time it is in swedish. function.
this mqtt_query = mqtt_query.decode("utf-8")
stops my functions.
Script:
def on_message(self, client, userdata, msg):
if self.can_start_conversation == True:
print("Message from MQTT: "+str(msg.payload.decode("utf-8")))
mqtt_query=str(msg.payload)[1:]
print(mqtt_query)
if 'custom' in mqtt_query.lower():
mqtt_query=mqtt_query.lower()
mqtt_queryidx=mqtt_query.find('custom')
mqtt_query=mqtt_query[mqtt_queryidx:]
mqtt_query=mqtt_query.replace('custom',"",1)
mqtt_query=mqtt_query.strip()
self.custom_command(mqtt_query)
else:
self.assistant.send_text_query(mqtt_query)
terminal:
ON_MUTED_CHANGED:
{"is_muted": false}
ON_START_FINISHED
ON_MEDIA_STATE_IDLE
Connected with result code 0
Message from MQTT: Vad är klockan
'Vad \xc3\xa4r klockan'
ON_CONVERSATION_TURN_STARTED
E0114 09:02:06.253649187 3782 fork_posix.cc:63] Fork support is only compatible with the epoll1 and poll polling strategies
ON_RESPONDING_STARTED:
{"is_error_response": false}
ON_RESPONDING_FINISHED
modified script:
def on_message(self, client, userdata, msg):
if self.can_start_conversation == True:
print("Message from MQTT: "+str(msg.payload.decode("utf-8")))
mqtt_query=str(msg.payload)[1:]
print(mqtt_query.decode("utf-8"))
if 'custom' in mqtt_query.lower():
mqtt_query=mqtt_query.lower()
mqtt_queryidx=mqtt_query.find('custom')
mqtt_query=mqtt_query[mqtt_queryidx:]
mqtt_query=mqtt_query.replace('custom',"",1)
mqtt_query=mqtt_query.strip()
self.custom_command(mqtt_query)
else:
self.assistant.send_text_query(mqtt_query)
terminal:
ON_MUTED_CHANGED:
{"is_muted": false}
ON_START_FINISHED
ON_MEDIA_STATE_IDLE
Connected with result code 0
Message from MQTT: Vad är klockan
Please look at the commit referenced above.
Now its working with custom actions... native functions only work with english commands (swedish also but without å ä ö).
When I use Google cloud. It speak fast. Can I add "speakingRate" here somewhere? https://github.com/shivasiddharth/GassistPi/blob/a2cbf57ca0c40c43c17a0b4b5e2f393c5a38fc70/src/actions.py#L279
A function like " Repaet after me" or "say" would be useful. If I say " Repeat after me, Hi I'm new to google assistant " or similar Then GassistPi replays: " Hi I'm new to google assistant "
With this I can send out custom tts to my GassistPi from my domoticz via mqtt.