Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to trigger mic of headless client remotely? #75

Open
gafk opened this issue Oct 2, 2020 · 17 comments
Open

How to trigger mic of headless client remotely? #75

gafk opened this issue Oct 2, 2020 · 17 comments

Comments

@gafk
Copy link

gafk commented Oct 2, 2020

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.

@fquirin
Copy link
Contributor

fquirin commented Oct 5, 2020

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.

@gafk
Copy link
Author

gafk commented Oct 11, 2020

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
Copy link
Author

gafk commented Oct 22, 2020

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...

@fquirin
Copy link
Contributor

fquirin commented Oct 24, 2020

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
Copy link
Contributor

fquirin commented Oct 24, 2020

I just remembered something 😁
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 🙂
Not super elegant yet but also not too complicated ^^. Let me know if this helps .

@gafk
Copy link
Author

gafk commented Oct 26, 2020

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.

@fquirin
Copy link
Contributor

fquirin commented Oct 26, 2020

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.

@gafk
Copy link
Author

gafk commented Oct 27, 2020

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?

@fquirin
Copy link
Contributor

fquirin commented Oct 29, 2020

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 ;-)

@gafk
Copy link
Author

gafk commented Oct 30, 2020

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?

@fquirin
Copy link
Contributor

fquirin commented Nov 5, 2020

Oh I totally forgot about that 😅
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 :-)

@gafk
Copy link
Author

gafk commented Nov 6, 2020

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

@gu3nter
Copy link

gu3nter commented Nov 8, 2020

@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

@fquirin
Copy link
Contributor

fquirin commented Nov 9, 2020

Hi @gu3nter does this help maybe? :-)

@gu3nter
Copy link

gu3nter commented Nov 10, 2020

@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 ''

@fquirin
Copy link
Contributor

fquirin commented Nov 10, 2020

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"
}'

@gu3nter
Copy link

gu3nter commented Nov 11, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants