Google HomeでVoiceTextの話者と感情をランダムにする

概要

VoiceTextで、様々な声でGoogle Homeに喋らせることができますが、 感情や話者の組み合わせがいろいろできるけど、 どの組み合わせが良いのかわからないので、 ランダムにしてみました。

VoiceTextWriter.jsを編集する。

VoiceTextWriter.jsを編集して、話者と感情がランダムに選択されるように修正しました。 前提としては、Google homeでVoiceTextの設定をしてあることです。
var fs = require('fs');
var VoiceText = require('voicetext');

//APIキーを入力。取得したAPIキーを入力します。
var voice = new VoiceText('xxxxxxxxxxxxxxxxxxx');
var OUT_PATH = '/home/pi/homebot/voice/_temp.wav'

//IPアドレスを入力する。
var OUTPUT_URL = 'http://192.168.x.xx:9000/_temp.wav';

// set spearker at random
var array = [voice.SPEAKER.HIKARI, voice.SPEAKER.HARUKA,voice.SPEAKER.TAKERU,voice.SPEAKER.SHOW,voice.SPEAKER.BEAR,voice.SPEAKER.SANTA];
var mySpeaker = array[Math.floor(Math.random() * array.length)];

// set emotion at random
var array2 = [voice.EMOTION.HAPPINESS, voice.EMOTION.ANGER,voice.EMOTION.SADNESS];
var myEmotion = array2[Math.floor(Math.random() * array2.length)];

console.log("Speaker:" + mySpeaker + ", Emotion:" + myEmotion);

class VoiceTextWriter{

convertToText(text){
return new Promise(function(resolve,reject){
voice

.speaker(mySpeaker)
.emotion(myEmotion)
.emotion_level(2) // 感情レベル。1〜4を指定。数値が大きいほど感情が強。
.pitch(95)  // 50から200(%)まで。値が小さいほど低い音になります。
.speed(95)  // 50から400(%)まで。値が小さいほど遅い話し方になります。
.volume(150) // 50から200(%)まで。値が小さいほど小さい音になります。
.speak(text, function(e, buf){
    if(e){
      console.error(e);
      reject(e);

    }else{
    fs.writeFileSync(OUT_PATH, buf, 'binary');
  resolve(OUTPUT_URL);
    }
  });
});
}
}
module.exports = VoiceTextWriter;

参考

下記サイトを参考にしてランダムにしました。

コメント

このブログの人気の投稿

Youtubeの音楽をGoogle Homeで再生

Google HomeでViceTextによる音声の変更

Google Home mini をカスタマイズしてよかったこと、イマイチだったこと

100均のフレキシブルスマートフォンスタンドでGoogle Home miniをリビングの電子ピアノに固定

修正メモgoogle-tts-api

Google HomeからRM Mini3を経由してテレビを操作

Google Home からガラケーにメール、ガラケーからのメールをGoogle Homeで読み上げる

Raspberry Pi3にhubotをインストールする