Top > 日記 > 2014-07-21

しゃべらすシリーズ(その2)

リフレクターに接続しているときに、そのリフレクターにLINK / UNLINK してくる局名をしゃべらす。*1
今回は、php とtext2speech.shを使う。

  1. Link/Unlink局の切り出し
    /usr/bin/php を利用するので、Raspberry Piに apache2、php5 をInstallしておく。最初に以下のphpファイルを/var/www/htmlに作成し、ブラウザで開けることを確認し、OKであれば、/rootに置く。ここで作ったphpを利用。
    ---- h2t_REF047.php ---
    <html>
    <head>
    <!--<meta http-equiv="refresh" content="12">-->
    <meta http-equiv="Content-Type" content="text/html; charset=x-sjis">
    <title>REF047_IN/OUT STATUS</title>
    </head>
    <body>
    
    <?php
    $tmp_f = "/home/pi/call_o.txt"; //現時点での接続局リスト
    $con_f = "/home/pi/conn.txt";   //今接続してきた局リスト
    $discon_f = "/home/pi/discon.txt"; //今切断した局リスト
    $str_n = "";
    $call_t = "";
    
    if (file_exists($tmp_f)){
      $call_t = file($tmp_f);
      unlink($tmp_f);
    }
    
    //print "Old_file = " . $call_t[0] . "<BR>";
    
    $source_file = "http://ref047.dstargateway.org/";
    $fp_in  = fopen($source_file, "r");
    $i = 0;
    $j = 0;
    $k = 0;
    
    //$call_o = array("JL3ZBS","JJ1YEG","JQ1ZKF","JH1BLT");
    //print "debug::" ; print_r ($call_o); print "<BR>";
    
    while (! feof($fp_in)) {
      $str[$i] = trim(fgetss($fp_in, 1000));
    //      print $i . ")" . $str[$i] . ":::" . strrpos($str[$i],"ype") . "<BR>";
      if (strrpos($str[$i],"ype") == 1) {
        $j = $i;
      }
      if (strrpos($str[$i],"ast Heard") == 1) {
        $k = $i;
      }
      $i++;
    }
    fclose($fp_in);
    array_shift ($str);
    //print_r($str);
    
    $j = $j + 2;
    $k = $k - 7;
    //print $j.":".$k."<BR>";
    
    for($i = $j; $i < $k; $i++){
        $str_a = substr($str[$i],0,6) . ",";
        $str_n = $str_n . $str_a;
        $i = $i + 5;
    }
    
    //print "New_file= " . $str_n . "<BR>";
    
    $fno = fopen($tmp_f, "w");// call_o.txt
    fwrite($fno, $str_n);
    fclose($fno);
    
    $call = split(",",$str_n);// to array $call
    sort($call);
    //print "New(Sort): "; print_r ($call);
    //print "<BR>\r\n";
    
    $call_o = split(",",$call_t[0]);
    sort($call_o);
    //print "Old&nbsp;&nbsp;(Sort): "; print_r ($call_o);
    //print "<BR>\r\n";
    
    $fo_con = fopen($con_f, "w");
    $diff1 = array_diff($call, $call_o);
    while(list($key,$val) = each($diff1)) {
      if(strlen($val) > 0){
        print $val . " Connected<br>";
        fwrite($fo_con, $val." ");
      }
    }
    print "<BR>";
    fclose($fo_con);
    
    $fo_discon = fopen($discon_f, "w");
    $diff2 = array_diff($call_o, $call);
    while(list($key,$val) = each($diff2)) {
      if(strlen($val) > 0){
        print $val . " disconnected<br>";
        fwrite($fo_discon, $val." ");
      }
    }
    print "<BR>";
    fclose($fo_discon);
    ?>
  2. text2speech.shで発声させる
    上記phpを/usr/bin/php で実行し、discon.txtかconn.txtが0バイトでなければtext2speechで発声する。
    --- inout.sh ---
    #!/bin/bash
    
    while :
    do
      /usr/bin/php /root/h2t_REF47.php > /dev/null
      sleep 1
      if [ -s /home/pi/conn.txt ]; then
         MSG=`cat /home/pi/conn.txt`
         echo $MSG
         /home/pi/bin/text2speech.sh "$MSG connected."
         rm -f /home/pi/conn.txt
         touch /home/pi/conn.txt
      fi
      if [ -s /home/pi/discon.txt ]; then
         MSG=`cat /home/pi/discon.txt`
         echo $MSG
         /home/pi/bin/text2speech.sh "$MSG disconnected."
         rm -f /home/pi/discon.txt
         touch /home/pi/discon.txt
      fi
    sleep 2
    done
  3. inout.shを自動起動させる
    --- /etc/ ---
    # Print the IP address
    _IP=$(hostname -I) || true
    if [ "$_IP" ]; then
      printf "My IP address is %s\n" "$_IP"
      /home/pi/bin/atk "IPアドレスは,$_IPです"
    fi
    /root/inout.sh &  # ← 追加 
    exit 0
     
    2015 8/1 からgoogle tts が利用できなくなった

    google tts が利用できなくなったので、AquesTalkを使うことにした。日記10月1日に載せた/root/henkan を通すと数字が英語読みになる。


    URL B I U SIZE Black Maroon Green Olive Navy Purple Teal Gray Silver Red Lime Yellow Blue Fuchsia Aqua White


*1 拡張子は含まない

リロード   新規 下位ページ作成 凍結解除 差分 コピー 名前変更   ホーム 一覧 検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: Sun, 04 Oct 2015 11:36:17 JST (3129d)