Russification of voice acting Xiaomi Robot Vacuum

  • Tutorial
image

Greetings!


There is such a wonderful python-miio library that allows you to control many Xiaomi gadgets : a vacuum cleaner, air purifier / humidifier, lamps, etc. In the process of reading the documentation, I came across a generally useless, but entertaining opportunity to replace the standard voice acting of a robot vacuum cleaner with my own. And since I haven’t come across anything like this at Giktimes, and Xiaomi household gadgets are popular, I decided that maybe the description of the process would be useful to someone.

0. python-miio


It all starts with the library. At a minimum, it is good in that it allows you to abandon the proprietary Xiaomi application and generally block IoT gadgets from accessing the Internet, limiting itself to an isolated LAN.

In addition to Python 3, installation is required libffi-dev libssl-dev и ccrypt.

We carry out:

pip3 install -U setuptools
pip3 install python-miio

On the Mac and Debian (Raspberry Pi), no more 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 perhaps the most dull part. If you don’t need to get attached to the Xiaomi application (python-miio allows you to configure wi-fi and a schedule without MiHome, however, you can’t see a map for example), then
There is an easy way:
  • reset Wi-Fi settings by simultaneously pressing two buttons on the robot
  • connect to the access point created by the vacuum cleaner
  • perform
    mirobo discover --handshake 1
    and get ip and token
  • Next, you can configure Wi-Fi
    mirobo configure_wifi 
    and so on, cm mirobo --help


If you need additional chips without the official MiHome application , in any way, then put it, register, add a vacuum cleaner in a regular way, then
in case of iOS:
  • make unencrypted backup via iTunes
  • open the backup using iBackup Viewer (the software is paid, but the limitations of the free version will not hinder our goals), in it we select the file system view (raw files) and look for the Xiaomi MiHome application (com.xiaomi.mihome). We extract one file with the name <digits> _mihome.sqlite
  • open the resulting database, for example, DB Browser for SQLite . From there, you can extract the parameters for all devices, in particular the token we need (field ZTOKEN).
  • then open the Terminal and execute
    echo '0: <извлеченный_токен>' | xxd -r -p | openssl enc -d -aes-128-ecb -nopad -nosalt -K 00000000000000000000000000000000


in case of Android:
You will need adb. We make a backup of the base

adb backup -noapk com.xiaomi.smarthome -f backup.ab

using ADB Backup Extractor we extract the contents

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 extract the token we need ( ZTOKEN field ).

Instead of viewing the obtained databases manually, you can use the tool from the python-miio library, it should work with the databases with both Android and iOS:

miio-extract-tokens <файл_бд>

The most boring part is behind, the part ahead is creative.

2. Voice acting


I used a ready-made script . We clone to ourselves, you only need a folder 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 I needed to make a couple of corrections:

84.  os.system("say -v <голос> -o " + path + " --data-format=LEI16@22050 " + text)

Everything is simple with a voice, choose the one you like (the whole list can be viewed by typing in the Terminal)

say -v ?

I put the Russian voice Milena. Pay attention to the --data-format parameter , in the original script the author uses LEF32 @ 22050 , but with this attribute the robot gave me silence. Looking at the output of ffmpeg, I saw that the original voice acting uses pcm_s16le , so I changed the parameter to LEI16 in the script , after which everything worked. I have the first generation of a vacuum cleaner, maybe the second has a different audio file format, however, if the robot is silent, I recommend first of all to make sure that the audio files have the same parameters.

Having corrected the script, we go to ./languagewhere the lists of phrases are stored. We duplicate any, rename it to audio_ru.csv and edit as you like. After we run the script

./generate_audio.py

choosing our file with phrases (audio_ru.csv) and tts-engine in interactive mode. At the output, we get the ru.pkg file , which you need to fill in with the command

mirobo install_sound ./ru.pkg

after completing

export MIROBO_TOKEN=<токен>

and

export MIROBO_IP=

3. Departed for the future


In principle, all of the above is in the documentation for the python-miio library, but I hope this mini-manual is still useful to someone) Taking this opportunity, I want to ask: will another article on “smart home” be interesting? The fact is that for quite a long time I have been building a home ecosystem based on devices from Xiaomi and Philips, but without branded applications, the Home Assistant rules everything. This occupation is quite endless, 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 the operating experience, the jambs and the errors that I encountered. Perhaps my experience would save someone from the same rake, or threw new ideas.

UPDAdded a proven way to get a token without binding to MiHome.

Only registered users can participate in the survey. Please come in.

Do I need another article about the "smart" home?

  • 87.7% Yes 179
  • 12.2% No, they are already over 9000 25

Also popular now: