
Greetings
There is such a wonderful library
python-miio , which allows you to control many
Xiaomi gadgets: a vacuum cleaner, an air purifier / humidifier, lamps, and so on. In the process of reading the documentation, I came across a generally useless, but entertaining opportunity to replace the standard voice of the robot vacuum cleaner with my own. And since I never had anything like that on Hiktatimes, and Xiaomi household gadgets are popular, I decided that perhaps the description of the process would be useful for someone.
0. python-mio
It all starts with the library. At a minimum, it is good because it allows you to abandon the proprietary application Xiaomi and generally close IoT gadgets access to the Internet, limiting itself to an isolated locking device.
In addition to Python 3, installation will require
libffi-dev libssl-dev ccrypt
.
')
We carry out:
pip3 install -U setuptools pip3 install python-miio
On Mac and Debian (Raspberry Pi), no further dependencies were required.
1. Device Tokens
To communicate with Xiaomi devices, you need to get device tokens (in this case, a vacuum cleaner), this is probably the most dismal part. If you do not need to bind to the Xiaomi application (python-miio allows you to configure wi-fi and the schedule without MiHome participation, however, you can’t see the map for example)
If you need additional chips and without the official
MiHome application, in any way, then we put it, register, add the vacuum cleaner in a regular way, then
in the case of Android:It will take adb. Making a base backup
adb backup -noapk com.xiaomi.smarthome -f backup.ab
using ADB Backup Extractor extract content
java -jar Android\ Backup\ Utilities/Android\ Backup\ Extractor/android-backup-extractor-20171005-bin/abe.jar unpack backup.ab unpacked.tar
and unpack
tar -xvf unpacked.tar
from the resulting database, using, for example,
DB Browser for SQLite, we retrieve the token we need (the
ZTOKEN field).
Instead of viewing the resulting databases manually, you can use the tool from the python-miio library, it should work with databases from both Android and iOS:
miio-extract-tokens <_>
The most boring part behind, in front of the creative.
2. voice acting
I used the
finished script . We clone to ourselves, only the
dustcloud/devices/xiaomi.vacuum/audio_generator
. Edit the
generate_audio.py script. I did everything on the Mac and, accordingly, used its speech generator, but it took me to make a couple of edits:
84. os.system("say -v <> -o " + path + " --data-format=LEI16@22050 " + text)
With a voice, everything is simple, choose the one you like (the entire list can be viewed by typing in the Terminal)
say -v ?
I put the Russian voice Milena. Pay attention to the
--data-format parameter, the author uses
LEF32 @ 22050 in the original script, but with this attribute the robot gave me silence. Looking at the ffmpeg output, I saw that
pcm_s16le is used in the original voice acting, so I changed the parameter in the script to
LEI16 , after which it all worked. I have the first generation of a vacuum cleaner, perhaps the second is a different format of sound files, however, if the robot is silent, I recommend first of all to make sure that the sound files have the same parameters.
Having corrected the script, go to
./language
, where the lists of phrases are stored. Duplicate any, rename to
audio_ru.csv and rule as you please. After we run the script
./generate_audio.py
by selecting our phrase file (audio_ru.csv) and the tts-engine in interactive mode. At the output, we obtain the file
ru.pkg , which needs to be poured onto the vacuum cleaner with the command
mirobo install_sound ./ru.pkg
after completing
export MIROBO_TOKEN=<>
and
export MIROBO_IP=<ip- >
3. Reserve for the future
In principle, all of the above is in the documentation for the python-miio library, but I hope this mini-manual will still be useful to someone) Taking this opportunity, I want to ask: will there be another interesting article on a smart home? The fact is that I have been building a home ecosystem for quite a long time on the basis of Xiaomi and Philips devices, but without proprietary applications, Home Home Assistant is running all of them. Occupation is quite an infinite, but at the moment the system has come to a more or less stable form.
On the one hand, Geektimes is full of similar articles, on the other - I would like to put more emphasis on operating experience, jambs and errors that I encountered. Perhaps my experience would have saved someone from the same rake, or threw new ideas.
UPD. Added a proven way to get a token without binding to MiHome.