Two Way Audio with XiaoFang Hack

XiaoFang IP Camera with samtap’s fang-hacks (https://github.com/samtap/fang-hacks), you can get 2-way audio with a little trick:

1. download necessary files (from https://github.com/samtap/fang-hacks/issues/305) and put it on /media/mmcblk0p2/snx_audio (dont forget to set permission execute):
- snx_audio_playback
- snx_audio_record

2. remote speaker:
# set gpio
gpio_ms1 -n 7 -m 1 -v 1
# listen audio data in port 11032 on camera
tcpsvd 0.0.0.0 11032 /media/mmcblk0p2/snx_audio/snx_audio_playback -d s16 -s 32k -f -
# stream audio from pc to camera
ffmpeg.exe -i input -ar 16k -f s16le tcp://your-cam-ip:11032

2b. alternative one-line:
ffmpeg.exe -i input -ar 16k -f s16le - | ssh root@your-cam-ip /media/mmcblk0p2/snx_audio/snx_audio_playback -d s16 -s 32k -f -

3. remote mic (disable snx_rtsp_server audio first at /media/mmcblk0p2/data/etc/scripts/20-rtsp-server):
# listen port 12016, ready to stream audio data
tcpsvd 0.0.0.0 12016 /media/mmcblk0p2/snx_audio/snx_audio_record -d s16 -s 16k -f -
# play on pc
ffplay -f s16le -ar 16k -ac 1 -nodisp tcp://your-cam-ip:12016

3b. alternative one-line:
ssh root@your-cam-ip /media/mmcblk0p2/snx_audio/snx_audio_record -d s16 -s 16k -f - | ffplay -f s16le -ar 16k -ac 1 -nodisp -

4. Enable SSH key login (the /root home directory isn’t writable so we have to move it):
cp -r /root /media/mmcblk0p2/
sed -i 's#/root#/media/mmcblk0p2/root#g' /etc/passwd
mkdir -p /media/mmcblk0p2/root/.ssh
chmod 700 /media/mmcblk0p2/root/.ssh
touch /media/mmcblk0p2/root/.ssh/authorized_keys
chmod 600 /media/mmcblk0p2/root/.ssh/authorized_keys
echo 'YOUR_KEY_HERE' >> /media/mmcblk0p2/root/.ssh/authorized_keys

Source:
– https://github.com/samtap/fang-hacks/blob/ca435dd90e1bf290d58d31874be594af34cf21a5/INSTALL.md
– https://github.com/samtap/fang-hacks/issues/305
– https://github.com/samtap/fang-hacks/issues/310
– https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks/issues/718

Leave a Reply

Your email address will not be published. Required fields are marked *