Page 1 of 1

Xiaomi Gateway custom MP3

Posted: Wednesday 14 March 2018 11:19
by Egregius
Hi All,

I'm trying to upload a custom made MP3 to my Xiaomi gateway to be used as notification sound.
Took a while to figure out that I needed a Android device to do that, iOS only support recording voice messages.
Anyway, the voice recordings work, the uploaded MP3 works, but plays at double the speed getting a voice like the Chipmunks.
What are the requirements for the MP3?

Re: Xiaomi Gateway custom MP3

Posted: Sunday 18 March 2018 21:25
by BarryT
i guess 128kbs - 44.1khz, mono (or maybe stereo also works)

when you say it plays at double speed, i think it has something to do with the sampling frequency of the audio file.
try to update its file to 44.1khz, and upload again, or try to upload a 22khz version..

i'm not sure the exact reason its double speed, but in here its working perfect! :)

Re: Xiaomi Gateway custom MP3

Posted: Sunday 18 March 2018 23:13
by Egregius
With wich program did you create the mp3?

Re: Xiaomi Gateway custom MP3

Posted: Sunday 18 March 2018 23:27
by BarryT
FL Studio :)
But it can with every program as long there is a mp3 encoder in it.

Re: Xiaomi Gateway custom MP3

Posted: Thursday 05 April 2018 17:16
by advokatb
Can you please share how to play custom mp3 in Blocks?
dom.PNG
dom.PNG (18.42 KiB) Viewed 10083 times
I've added Xiaomi Gateway MP3 block but it doesn't play nothing :(
Thanks.

Re: Xiaomi Gateway custom MP3

Posted: Thursday 05 April 2018 17:45
by Egregius

Re: Xiaomi Gateway custom MP3

Posted: Wednesday 11 July 2018 8:19
by klirik
Actually it is not mp3, but aac
(have tried mp3 directly, gateway doesn't play it)
64k aac is ok.

(I believe miHome makes conversion via xiaomi's cloud when accept mp3 in application, but I've tried directly uploaded file)

Re: Xiaomi Gateway custom MP3

Posted: Friday 13 July 2018 7:23
by klirik
Need miio (any flavour - php-miio, python-miio, etc.) and available gateway token and IP (token you can look in mihome, at page where you switch on developer's mode).

1. Convert the source mp3 into aac for gateway:

Code: Select all

ffmpeg -i 18Track.mp3 -b:a 64k tr18a.aac
2. Place converted file into place available from gateway by http (m.b. other proto works also; didn't check).
I used webserver on my router; but it is also possible to make it available via dz (however it doesn't return correct mimetype for aac, but downloading via it still works).

3. Via miio with correct ip/token send the command:

Code: Select all

{"id":1,"method":"download_user_music","params":["5001","http://192.168.1.150/media/music/tr18.aac"]}
Here first param is musicID, must be >=1000. Second is url where gateway will take the music.

4. Periodically check the progress (since donwload command is async):

Code: Select all

{"id":1,"method":"get_download_progress","params":[]}
It will return progress for each music ID in %. Finally you'll take:

Code: Select all

{"result":["5001:100"],"id":1}
5. Play the music. There are two possible ways: by MusicID (which is string), or by index (which is numeric). In first case you can also set the volume

Code: Select all

{"id":1,"method":"play_music","params":[5001]}

Code: Select all

{"id":1,"method":"play_music_new","params":["5001",10]}
Now you can set MusicID as the custom variable and play/stop it via existing xiaomi gateway buttons. In MiHome this record will be nameless.

Other useful commands are

Code: Select all

{"id":1,"method":"get_music_info","params":[0]}
- get list of available music (params m.b. 0,1,2 for 'system' banks, >2 will return list of user music).

Code: Select all

{"id":1,"method":"delete_user_music","params":["5001"]}

Code: Select all

{"id":1,"method":"get_music_free_space","params":[]}
- returns available bytes. On 'fresh' gw it is about 11Mb available.

Re: Xiaomi Gateway custom MP3

Posted: Friday 28 September 2018 10:19
by Recky
Could you eleborate step 3? "Via miio with correct ip/token send the command"

What is the command to connect to the gateway with miio? I cannot figure it out. Tried both miio and python-miio, but there is just no good documentation how to run the commands correctly.

Re: Xiaomi Gateway custom MP3

Posted: Wednesday 12 December 2018 4:28
by klirik
As an example:

Code: Select all

php miio-cli.php --ip 192.168.1.123 --token 3XXXXXXXXXXXXXXXXXXXXXXXXXXXXX22 --sendcmd '{"id":1,"method":"get_music_free_space","params":[]}’
Actually I've just wrapped all this long thing into a 1-line script which takes the command and add all this long stuff before it, like

Code: Select all

#!/bin/bash
php miio-cli.php --ip 192.168.1.123 --token 3XXXXXXXXXXXXXXXXXXXXXXXXXXXXX22 --sendcmd \'$1\’
and invoke it as

Code: Select all

./gateway "{"id":1,"method":"download_user_music","params":["5001","http://192.168.1.150/media/music/tr18.aac"]}"
but this is already small details, you can guess your own comfortable way
(say, auto-increment 'id' param - it is ok to have one and same for gateway, but, say for mirobo it will not work. Encode 'method' as separate, and leave only 'params' hand-coded).

Re: Xiaomi Gateway custom MP3

Posted: Sunday 01 December 2019 18:02
by Irek
It doesn't work to me at all. I don't know what I'm doing wrong.
My aac file is located on my RPI: /home/pi/Sounds/0001.aac and I've socond copy on dropbox.
If I execute command:
php miio-cli.php --ip 192.168.1.XXX --token XXX --sendcmd '{"id":1,"method":"download_user_music","params":["10003","https://www.dropbox.com/s/7v6ixits5dwrc7k/0001.aac"]}'
I receive: Устройство 192.168.1.XXX доступно и ответило:
{"result":["ok"],"id":1}
Looks like everything is OK, but aac file is not uploading to my gateway.
DevType is 1066.
I don't want to upload files using mic in my iPhone because of poor quality of the sound. Can you help me somehow to do it using cli?