Play Your Favourite Music Files on your SUSI Smart Speaker
The SUSI smart speaker supports playing local music from any USB device connected to the smart speaker. To play your favourite music directly from files, just put them in a thumb drive and plug it into any one of the four USB ports on the smart speaker. SUSI can either play all songs from the USB device or songs from a specific artist, genre or album. Working The first thing that needs to be done is to automount the thumb drive in the smart speaker, for this the usbmount package is used. Further, after the mount is done local skills are created which are then used by the SUSI server to interpret voice commands related to offline music playback. Breakdown The code which enables the above functionality is : Add dependency - https://github.com/fossasia/susi_installer/blob/1a2950b0eb1f88d4ecbd5b3c348d9b67ac2f4705/install.sh#L287 # usbmount is needed to automount usb drives on susibian(raspbian lite)if [ $targetSystem = raspi ] ; then DEBDEPS="$DEBDEPS hostapd dnsmasq usbmount"fi USB mount is added to the dependency list if the installer is running on a Raspberry Enable offline skills - https://github.com/fossasia/susi_installer/blob/1a2950b0eb1f88d4ecbd5b3c348d9b67ac2f4705/install.sh#L881 mkdir -p $WORKDIR/susi_server_data/generic_skills/media_discoverytouch $WORKDIR/susi_server_data/generic_skills/media_discovery/custom_skill.txtmkdir -p $WORKDIR/susi_server_data/settingsecho "local.mode = true" > $WORKDIR/susi_server_data/settings/customized_config.properties Enable the server to work with offline skills stored on the device. The new skills related to offline music playback are stored in /susi_server_data/generic_skills/media_discovery in a file named custom_skill.txt. Creating on the fly skills - https://github.com/fossasia/susi_installer/blob/1a2950b0eb1f88d4ecbd5b3c348d9b67ac2f4705/install.sh#L758 echo "Preparing USB automount"# systemd-udevd creates its own filesystem namespace, so mount is done, but it is not visible in the principal namespace.sudo mkdir /etc/systemd/system/systemd-udevd.service.d/echo -e "[Service]\nPrivateMounts=no" | sudo tee /etc/systemd/system/systemd-udevd.service.d/udev-service-override.conf# readonly mount for external USB drivessudo sed -i -e '/^MOUNTOPTIONS/ s/sync/ro/' /etc/usbmount/usbmount.confsudo cp $INSTALLERDIR/raspi/media_daemon/01_create_skill /etc/usbmount/mount.d/sudo cp $INSTALLERDIR/raspi/media_daemon/01_remove_auto_skill /etc/usbmount/umount.d/ First an override rule is added, which changes `PrivateMounts` rule’s value to `no` in /lib/systemd/system/systemd-udevd.service. PrivateMounts if set to yes, the processes of this unit will be run in their own private file system (mount) namespace with all mount propagation from the processes towards the host's main file system namespace turned off. This means any file system mount points established or removed by the unit's processes will be private to them and not be visible to the host. To learn more about mount namespaces read - http://man7.org/linux/man-pages/man7/mount_namespaces.7.html Next, whenever a device is mounted the 01_create_skill file is executed which contains the following instruction: python3 /home/pi/SUSI.AI/susi_installer/raspi/media_daemon/auto_skills.py "$UM_MOUNTPOINT" This calls the auto_skills.py file with the mount point of the storage device. The auto_skills.py file is used to generate audio skills for the USB drive. It scans for all the files in the USB thumb drive and creates relevant skills. Whenever the thumb drive is removed it calls out the 01_remove_auto_skill script which has the following instruction - echo -n > /home/pi/SUSI.AI/susi_server_data/generic_skills/media_discovery/custom_skill.txt This cleans out the custom_skills.txt file i.e. all the offline skills that were created for music playback are removed and the server no longer responds those skills. USAGE Play all music on the USB device Usage: SUSI, Play Audio This will play all audio from the USB device connected to the speaker. SUSI Smart speaker currently supports the following…
