あいつの日誌β

働きながら旅しています。

英語の勉強をしたくて学習スクリプトを書く

あらすじ

今働いている会社ではエンジニアのMTGが英語で行われております。 私は日本人エンジニアと相談しながら作業するので英語必須ではないのですが、まあどう考えても英語話せたほうが色々と話が早くなるのでとりあえず英語の勉強を始める事にしました。

作業環境

MacOSX でしか動かないのですが以下のような環境下で動作すると思います。

% sw_vers
ProductName:    Mac OS X
ProductVersion: 10.11.3
BuildVersion:   15D21

% node -v
v5.6.0

作戦

以下の機能を組み合わせます。

  • say コマンドで英単語を発音させる
  • notifier で発音した英単語と日本語訳を表示させる
  • cron で定期的に実行させる。

何をするかは以下のコマンドを実行させると分かりやすいと思います。terminal-notifierbrew install terminal-notifier で入ると思います。

% say -v alex -r 120 'hello, world'
% terminal-notifier -title 'hello' -message 'Hello, world!' 
% cat sample.js 
const CronJob = require('cron').CronJob;

new CronJob({
  cronTime: '*/1 * * * * *',
  onTick: () => { console.log('hello');}
}).start();
% node sample.js

やってみる

% mkdir study-english && cd $_
% npm init --yes
% npm install --save cron node-notifier lodash
% echo 'node_modules' > .gitignore
% git init && git add . && git commit -m 'initial commit'

create say.js:

const _ = require('lodash');
const CronJob = require('cron').CronJob;
const exec = require('child_process').exec;
const notifier = require('node-notifier');

const words = [
  {
    en: "We should think another task 30 minutes later",
    ja: "30分経って分からなかったら、別の問題を考えよう"
  }
];

const sayWord = () => {
  const word = _.sample(words)
  notifier.notify({
    title: word.en,
    message: word.ja
  });

  const command = `say -v alex -r 120 ${word.en}`;
  require('child_process').exec(command, (err, stdout, stderr) => {
    if (err) console.log(err);
  });
};

job = new CronJob({
  cronTime: '*/10 * * * * *',
  onTick: sayWord,
  start: true,
  timeZone: "Asia/Tokyo",
});

job.start();

説明

OSX には say コマンドという音声読み上げ機能が備わっています。オプションに声優を alex を指定して、読み上げ速度を1分間に120語程度に変更しています。このコマンドの詳解は man say を実行して下さい。

読み上げ速度を遅くしている理由はこちらの本に書いてある事を私が支持しているからです。

60歳からはじめられるゆっくりていねい英会話

あと、サンプルコードに書いてある例文は以下のサイトから引用しました。

http://blog.asial.co.jp/891

サンプルコードは一応ここに置いておきます。 ソースコード自体は共有するほどでもないのですが、役に立つフレーズがまとまったら更新しようかと思います。

GitHub - okamuuu/study-english

こちらからは以上です。