Created
July 18, 2015 15:15
-
-
Save ser1zw/6e7ce45a1721f5e1d1c1 to your computer and use it in GitHub Desktop.
Bluemix Watson の Speech To Text API をローカルから使用するサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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