IBM CloudのSpeech to Textというサービスを利用してみました。
サンプル
添付ファイルフィールドに音声ファイルを読み込んだ際に、文字列フィールドに文字を書き起こします。
デモには、http://www.voice-pro.jp/announce/の「G-01」を利用しました。
IBM Cloud設定
こちらを参考にSpeech to Text サービスを作成してください。 サービス作成後、管理画面に表示された「API鍵」をメモしておきます。
kintone設定
フォーム設定
コード
下記、「sample.js」を読み込みます。 「apiKey」には、「IBM Cloud設定」でメモした「API鍵」を設定します。
・sample.js
(function() {"use strict";kintone.events.on(['app.record.create.show','app.record.edit.show',
],function(event) {varapiUrl='https://gateway-tok.watsonplatform.net/speech-to-text/api/v1/recognize?model=ja-JP\_BroadbandModel';varapiKey='\*\*\*\*\*\*';document.addEventListener('change',function(e) {if(e.target.type!=='file')return;varfile=e.target.files[0];if(!file.type.match('audio.\*'))return;kintone.proxy.upload(
apiUrl,'POST',
{'Content-Type':file.type,'Authorization':'Basic '+btoa('apikey:'+apiKey)
},
{
format:'RAW',
value:file
}
).then(function(response) {varrecord=kintone.app.record.get();record.record.text.value=JSON.parse(response[0]).results.reduce(function(text,result) {returntext+result.alternatives[0].transcript.replace(/ /g,'')+'。';
},'');kintone.app.record.set(record);
});
},true);
});
})();
以前ご紹介した、MediaRecorder APIを使った録音機能やGASを使った自動翻訳機能などと組み合わせれば、便利なアプリが作れそうですね。