关闭

linux utf8转gb2312 声音播放脚本

321人阅读 评论(0) 收藏 举报
char* utf8_to_gb2312(char* inbuf)
{
  int inlen = strlen(inbuf);
  iconv_t cd = iconv_open("gb2312", "utf-8");
  if ((iconv_t)-1 == cd)
    {
      perror("iconv_open"); return NULL;
    }
  char *outbuf = (char *)malloc(inlen * 4 );
  bzero( outbuf, inlen * 4);
  char *in = inbuf;
  char *out = outbuf;
  size_t outlen = inlen *4;
  iconv(cd, &in, (size_t *)&inlen, &out,&outlen);
  outlen = strlen(outbuf);
  //printf("%s\n",outbuf);
  //free(outbuf);
  iconv_close(cd);
  return outbuf;
}

void show_cdu(char* buf)
{
  char* inbuf = buf;
  char* outbuf = utf8_to_gb2312(inbuf);
  CDisp_Clr_688_3();
  CDisp_Setfont_688_3(1);
  CDisp_Set_Abs_XY_688_3(1,1);
  CDisp_String_688_3((unsigned char*)outbuf);
  CDisp_Start_688_3();
  free(outbuf);
  return;
}
下面是播放声音的脚本:
#!/bin/bash

par1=`tr  '[a-z]' '[A-Z]' <<< "$1"`

if [ $par1 = "PLAY" ]
then
/cqcp/bin/pSound -r 48000 -b 8 -c 2 -f /cqcp/resources/succ.wav
fi

if [ $par1 = "STOP" ]
then
    tpid=`ps -ef | grep succ.wav | grep -v grep | awk '{print $2}'`
    kill -9 $tpid
fi

if [ $par1 = "VOL" ]
then
    echo $2 > mute
    if [ $2 -eq 0 ]; then
        amixer set Master 0% mute
    else
        amixer set Master $2% unmute
    fi
#./playSound dd.wav

#system("play xxx.wav");
#cat file /dev/dsp
#system("aumix xxxxxx")
fi


   
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:134320次
    • 积分:1857
    • 等级:
    • 排名:千里之外
    • 原创:20篇
    • 转载:221篇
    • 译文:0篇
    • 评论:6条
    最新评论