LoginSignup
0
0

More than 5 years have passed since last update.

RubyでAITalk WebAPIを叩いてみた

Posted at

概要

AITalk WebAPIをRubyで叩いてみました。

AITalk WebAPIとは

株式会社エーアイさんが提供している音声合成WebAPIです。

ソースコード

require 'net/http'
require 'uri'
require 'active_support'
require 'active_support/core_ext'

def say(text='')
  params = {
    username: <your_name>,
    password: <your_pass>,
    ext: 'wav',
    text: text,
    speaker_name: 'nozomi_emo'
  }
  endpoint = URI.parse('http://webapi.aitalk.jp/webapi/v2/ttsget.php' + '?' + params.to_query)

  res = Net::HTTP.get_response(endpoint)

  case res
  when Net::HTTPSuccess
    file_name = "ai.wav"
    File.binwrite(file_name, res.body)
    `afplay ai.wav`
    File.delete(file_name)
  else
    puts "failed"
  end
end

参考

以下のサイトを参考にしました。
http://fromatom.hatenablog.com/entry/2015/01/21/201740

0
0
0

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
0
0