sepia-docs icon indicating copy to clipboard operation
sepia-docs copied to clipboard

How to trigger mic of headless client remotely?

Open gafk opened this issue 3 years ago • 17 comments

After some struggle (mostly due to my lack of knowledge...) I was able to setup a headless client on my raspberry pi 4. It is connected to my SEPIA server running on my Synology via Docker and is working nicely. As discussed before, I also am not totally happy with the wake-word performance. I would like to remotely trigger the mic (e.g. by using a remote control that is already integrated into my openhab installation). I had a look at the API, but unfortunately I don't have any experience with Javascript, JSON, etc.

What I would like:

option a) Open an URL that triggers the mic on the client option b) Use a script with "curl" to triggr the mic

From what I saw I think this is possible, I am just lacking the skills to create the right url / curl.

gafk avatar Oct 02 '20 06:10 gafk

Hi,

there are a couple of options, I've been using a BLE beacon via MicroBit for a while, but HTTP remote actions are probably easier and can be sent directly to the SEPIA server or to the specific DIY client CLEXI server. The server version is the safest but requires authentication. Here is an example for user ID 'uid1007' and target device ID 'o1':

curl -X POST http://[SEPIA-server-IP]:20721/remote-action \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'GUUID=uid1007&PWD=[my-password-in-cleartext]\
&targetDeviceId=o1\
&action=%7B%22key%22%3A%22mic%22%7D&type=hotkey&client=my_remote'

Its probably not a good idea to store the password in clear-text ^^ so it would be better to get a 'KEY' token before or read the password from a safe place somehow. The CLEXI version works via it's 'HTTP event' endpoint is a bit less strict but I'd need to lookup the correct syntax because the CLEXI interface usually uses the WebSocket connection. Let me know if you want to try this one as well.

fquirin avatar Oct 05 '20 21:10 fquirin

Hi, works like a charm, thank you so much for your great work! I am now able to turn on the mic via an openhab switch item. This gives me me a whole lot of options on how to trigger my headless client (e.g. via a remote control, a motion detection sensor, etc.)!

gafk avatar Oct 11 '20 07:10 gafk

I have an additional question: Now that I can remotely trigger the mic from openhab, is there a similar way (via curl) to make my sepia client say a given string. For example having an openhab rule that triggers when the door was openend and have sepia say "The door was opened". I was able to create a .wav file via /tts but i failed when trying to make the client play this file...

gafk avatar Oct 22 '20 06:10 gafk

Hi,

actually I was thinking about the same issue yesterday inspired by another question I read. I think there might be a way to do it using a custom service because services can send "follow-up" messages (like the one used in the 'WorkoutHelperDemo' SDK service), but it seems unnecessarily complicated right now.

I'll come up with a better solution and report back soon ;-)

fquirin avatar Oct 24 '20 16:10 fquirin

I just remembered something :grin: The new version (v2.5.1) has support for remote-action media control. I'm using this to trigger radio music on any SEPIA client (with the same user logged in) via the updated radio cards context menu. Actually this can be used to remotely trigger any mp3 or wav file, so either you can prepare an mp3 to play or you can generate one via the TTS endpoint and then send this URL to SEPIA :slightly_smiling_face: Not super elegant yet but also not too complicated ^^. Let me know if this helps .

fquirin avatar Oct 24 '20 16:10 fquirin

Thanks for your reply. After updating server and client to the latest version , I was trying to play an MP3 like this:

curl -X POST http://localhost:20721/remote-action -H 'Content-Type: application/x-www-form-urlencoded' -d 'action={type=audio_stream&streamURL=http://url.to.my.mp3.&name=myStream}&type=media&targetDeviceId=o1&GUUID=uid1007&PWD=MYSAFEPASSWORD&client=my_remote'

It doesn't work, I am pretty sure there is a syntax error, unfortunately I am not an expert here...

Generally, I think having an easy way to make a Sepia client say a certain string would be a very common usecase for a smarthome setup. One way to do it might be to have an openhab String item that is monitored by Sepia and if an update is posted to that item (a new string), this string will be spoken. Something like that...

Or maybe just an easy endpoint that can be giving a string argument to be spoken.

gafk avatar Oct 26 '20 15:10 gafk

The 'action' has to be URL-encoded because of the content-type, this should work:

curl -X POST \
  http://localhost:20721/remote-action -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'GUUID=uid1007&PWD=MYSAFEPASSWORD&action=%7B%22type%22%3A%20%22audio_stream%22%2C%20%22streamURL%22%3A%20%22https%3A%2F%2Fexample.com%2Fmy-stream%22%2C%20%22name%22%3A%20%22My%20Stream%22%7D&type=media&targetDeviceId=o1&client=my_remote'

Or maybe just an easy endpoint that can be giving a string argument to be spoken.

I've put this on the top of the to-do list :-) and I'll think about the more specific issue of "observing" a value.

fquirin avatar Oct 26 '20 19:10 fquirin

Great, that works! Thanks a lot! Now just one more thing: Before the streaming starts, there is an audio notfication, something like "Habe einen Audio-Stream via Remote Zugriff empfangen. Stream wird gestartet." If I just want to play a quick message like "A window is open", I don't want this notification to be played before the actual message. is there a way to disable it?

gafk avatar Oct 27 '20 09:10 gafk

Right now this is necessary to avoid conflicts between user-interaction and remote-action, but you can change the text if you have access to www/scripts/sepiaFW.local (~/clexi/www/sepia/.. on the DIY client). Its in: StringsEN.remote_action_audio_stream and StringsDE.remote_action_audio_stream. Just put in whatever you want but make sure that its not empty ;-)

fquirin avatar Oct 29 '20 14:10 fquirin

Almost there :-) I changed the string to simply say my name before the stream starts, that's a good workaround. But what I realized just now is that there seems to be some sort of "fade-in" for the stream, meaning the playback starts on low volume and becomes louder. This is great for e.g. a radio stream, but not so much for a quick "the window is still open" notifications from openhab. Is there a way to disable this fade-in?

gafk avatar Oct 30 '20 12:10 gafk

Oh I totally forgot about that :sweat_smile: Unfortunately its not possible to deactivate this without messing with several other "features". I'll implement some new options soon and will post a preview here for testing :-)

fquirin avatar Nov 05 '20 09:11 fquirin

Ok, great! Looking forward to testing the new version. Thanks again for all your work!

gafk avatar Nov 06 '20 06:11 gafk

@fquirin could you post me this example below for the DIY Sepia-Client for Raspberry, please? (Clexi example)

curl -X POST http://[SEPIA-server-IP]:20721/remote-action \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'GUUID=uid1007&PWD=[my-password-in-cleartext]\ &targetDeviceId=o1\ &action=%7B%22key%22%3A%22mic%22%7D&type=hotkey&client=my_remote'

AS you mentioned in your first post on the top

gu3nter avatar Nov 08 '20 13:11 gu3nter

Hi @gu3nter does this help maybe? :-)

fquirin avatar Nov 09 '20 22:11 fquirin

@fquirin thanks for the answer, i will give that a try thease days, maybe you can check before, would be great, if my code will work.

Here will be my actual code which i generated with your help.

curl -X POST http://[SEPIA-server-IP]:20721/event/remote-button -H 'Content-Type: application/json &Clexi-id: 'clexi-123'' -d 'targetDeviceId=o1 &button=mic'

Could you check if this is correct, pelase? Maybe i have a few mistakes with the ''

gu3nter avatar Nov 10 '20 06:11 gu3nter

Hi @gu3nter, assuming your CLEXI IP would be 192.168.0.33 and Clexi-ID was clexi-123 this should work:

curl -X POST \
  http://192.168.0.33:9090/clexi/event/remote-button \
  -H 'Content-Type: application/json' \
  -H 'clexi-id: clexi-123' \
  -d '{
	"deviceId": "o1",
	"button": "mic"
}'

fquirin avatar Nov 10 '20 22:11 fquirin

oh nice thanks a lot, i will give that a try thease days, and let you know if it is working

Edit: works great, thanks

gu3nter avatar Nov 11 '20 06:11 gu3nter