LoginSignup
26
26

More than 5 years have passed since last update.

Intel Edisonを(かわいい声で)しゃべらせる

Last updated at Posted at 2014-12-09

 ネットワークにつなげる端末は,可能性が無限大だ.

準備

 今回はnode.jsでやります.
 以前の記事を参考に,EdisonからUSBオーディオを使えるようにしておいてください.

$ mkdir ~/voice
$ cd ~/voice
$ npm init

 何か色々と聞かれるので,適当に答えておいてください.

$ npm install Buffer --save
$ npm install request --save
# apt-get install alsa-utils

あと,スクリプトを実行するユーザーがaudioデバイスを扱えるグループに所属しているかを

$ id

で調べて,audioのグループに所属していなかったら,

# usermod -aG audio username

で,所属させておいてください.

プログラム

(かわいい声の)音声合成ですが,今回は,NICTの杉浦さんの「非モノローグ音声合成」を利用させてもらいます.これは,ロボット用の音声合成ソフトウェアとして開発されたもので,私が以前に書いた記事はこちら
 今見たら,PythonやC++はサンプルコードがありましたね.わざわざnode.jsで再実装する必要なかったな.

index.js
var req = require("request");
var Buffer = require("Buffer");
var fs = require("fs");
var exec = require("child_process").exec;

if(process.argv.length < 3){
    console.log("At least 1 argument is required.");
    return;
}

var word = process.argv[2];
console.log(word)

function playVoice(language, message){
    req.post( {
        url : "http://rospeex.ucri.jgn-x.jp/nauth_json/jsServices/VoiceTraSS",
        form : JSON.stringify({
            method : "speak",
            params : ["1.1", {"language" : language, "text" : message, "voiceType" : "*", "audioType" : "audio/x-wav"}]
        }),
        json : true
        },
        function(error, response, body){
            if(!error && response.statusCode == 200){
                buf = new Buffer(body["result"]["audio"], "base64");
                fs.writeFile("voice.wav", buf);

                exec("sleep 1");
                exec("aplay ./voice.wav -D plughw:1", 
                    function(err, stdout, stderr){
                        console.log(stdout);
                        console.log(stderr);
                    });
            }
        }
    ).on("response", function(res){
        console.log(res.statusCode);
    }).on("error", function(err){
        console.log(err);
    });
}

playVoice("ja", word);

$ node index.js こんにちは

上記のように起動してください.このプログラムはサーバーとデータをやりとりするので,Edisonをインターネットと接続する必要があります.

 NICTのサーバーに言葉を投げると,イイ感じにかわいくなった声のデータがbase64エンコードされて返ってきます.それをvoice.wavという名前でローカルに保存し,aplayで再生します.このとき,間にsleepをはさまないと失敗することが多かったです.

実験

 動画はこちら
 左上のスピーカーの表示が,ミュートになってないことを確認してください.

まとめ

  • NICTすげぇ
26
26
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
26