Page 1 of 1

Xiaomi Gateway custom MP3

Posted: Wednesday 14 March 2018 12: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 22: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: Monday 19 March 2018 0:13
by Egregius
With wich program did you create the mp3?

Re: Xiaomi Gateway custom MP3

Posted: Monday 19 March 2018 0: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 2136 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.