dingdang-respeaker-2017-11-06 发布



  • 更新详情

    • dingdang-2017-10-29 的基础上,加入 ReSpeaker 2mic 和 4mic 的驱动(没有 ReSpeaker 开发板的朋友请下载 dingdang-2017-10-29 版本镜像);

    • 将默认 STT 引擎改回 baidu-stt ,以避免因为中转服务器不可用导致 STT 失败的问题;

    • 提供一键切换驱动脚本,可以在 2mic/4mic 间切换。使用方法为:

      cd $HOME
      sudo ./switch.sh 型号  # 型号可以是 2mic 或 4mic
      
    镜像 md5 值 说明
    dingdang-respeaker-2017-11-06.img.gz 32ed3102bfa8f2308c56a42acb6693ac 备选百度云下载地址 (密码:r3n6)

    开发心得

    本次改动主要的目的是将 ReSpeaker 2mic 和 4mic 两个型号的驱动打包到一起发布,节省镜像的制作和发布成本。为了做到这一点,我编写了一个驱动切换脚本 switch.sh

    #!/bin/bash
    
    if [[ $EUID -ne 0 ]]; then
       echo "This script must be run as root (use sudo)" 1>&2
       exit 1
    fi
    
    is_Raspberry=$(cat /proc/device-tree/model | awk  '{print $1}')
    if [ "x${is_Raspberry}" != "xRaspberry" ] ; then
      echo "Sorry, this drivers only works on raspberry pi"
      exit 1
    fi
    
    card=$1
    
    if [ "x${card}" = "x" ] ; then
      echo "Usage: ./switch 2mic|4mic"
      exit 1
    fi
    
    cd /home/pi/dingdang
    case "${card}" in
       "2mic")
        echo "checkout to respeaker branch"
        git checkout respeaker
       ;;
       "4mic")
        echo "checkout to respeaker-4mic branch"
        git checkout respeaker-4mic
       ;;
       "*")
        echo "Please use 2mic or 4mic"
        exit 1
       ;;
    esac
    
    cd /home/pi/seeed-voicecard
    
    has_2mic=$(grep seeed-2mic-voicecard /boot/config.txt)
    has_4mic=$(grep seeed-4mic-voicecard /boot/config.txt)
    case "${card}" in
       "2mic") 
        echo "cp wm8960_asound.state /var/lib/alsa/asound.state"
        cp /home/pi/configs/2mic.asoundrc /home/pi/.asoundrc
        cp wm8960_asound.state /var/lib/alsa/asound.state
        cp asound_2mic.conf /etc/asound.conf
        if [ "x${has_4mic}" != x ] ; then
          echo "has 4mic before, now remove it"
          sed -i "s/dtoverlay=seeed-4mic-voicecard//g" /boot/config.txt
        fi
        grep -q "dtoverlay=seeed-2mic-voicecard" /boot/config.txt || \
          echo "dtoverlay=seeed-2mic-voicecard" >> /boot/config.txt
          
       ;;
       "4mic") 
        echo "cp ac108_asound.state /var/lib/alsa/asound.state"
        cp /home/pi/configs/4mic.asoundrc /home/pi/.asoundrc
        cp ac108_asound.state /var/lib/alsa/asound.state
        cp asound_4mic.conf /etc/asound.conf
        if [ "x${has_2mic}" != x ] ; then
          echo "has 2mic before, now remove it"
          sed -i "s/dtoverlay=seeed-2mic-voicecard//g" /boot/config.txt
        fi
        grep -q "dtoverlay=seeed-4mic-voicecard" /boot/config.txt || \
          echo "dtoverlay=seeed-4mic-voicecard" >> /boot/config.txt    
       ;;
       *) 
        echo "Please use 2mic or 4mic"
       ;;
    esac
    
    echo "------------------------------------------------------"
    echo "Please reboot your raspberry pi to apply all settings"
    echo "Enjoy!"
    echo "------------------------------------------------------"
    

    当切换驱动时,这个脚本主要执行如下几个操作:

    1. 将 dingdang 切换到对应型号的分支(2mic 对应 respeaker 分支,4mic 对应 respeaker-4mic 分支);
    2. 将目标型号的 .asoundrc 文件拷贝到 $HOME ,替换原来的 .asoundrc 。ReSpeaker 2mic 和 4mic 的 .asoundrc 区别在于一个带了音频输出口,一个不带,因此 PCM 的输出选择的 card 不同;
    3. 去除原来的驱动设置,改为适用于目标型号的驱动。这包括替换 /var/lib/alsa/asound.state/etc/asound.conf
    4. 将 boot/config.txt 里的驱动改为目标型号的驱动。

Log in to reply
 

Popular Topics

|

Looks like your connection to SCC was lost, please wait while we try to reconnect.