Skip to content

Instantly share code, notes, and snippets.

@ser1zw
Created July 18, 2015 15:15
Show Gist options
  • Save ser1zw/6e7ce45a1721f5e1d1c1 to your computer and use it in GitHub Desktop.
Save ser1zw/6e7ce45a1721f5e1d1c1 to your computer and use it in GitHub Desktop.
Bluemix Watson の Speech To Text API をローカルから使用するサンプル
require 'uri'
require 'net/http'
username = "<YOUR API KEY>"
password = "<PASSWORD>"
file = 'TEST.wav'
response = nil
url = 'https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?model=ja-JP_BroadbandModel'
uri = URI.parse(url)
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
# https.set_debug_output $stderr
data = open(file, 'rb') { |f| f.read }
request = Net::HTTP::Post.new(url)
request.basic_auth(username, password)
request["Content-Type"] = "audio/wav"
request["Transfer-Encoding"] = "chunked"
request.body = data
res = https.request(request)
puts res.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment