oxford-speech-api 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/oxford-speech-api.rb +61 -0
  3. metadata +58 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 197849d3bf50e20c55056188e092ffdf342c33a8
4
+ data.tar.gz: 0565cbe34442a906248ca37c9a67e2aefdcb19d6
5
+ SHA512:
6
+ metadata.gz: 4df76f84f2bd21640eaffc6aca98e99003713cb19d7eab5909a5a7349f5c7e4c3840c67e4d52eca2200fc321c95b04f7fa4c89e2f3e24b2e81608976f1a5e628
7
+ data.tar.gz: 148ec797af90b5bd5daa88e6aa3b2fb4d1cffcdee354f5bf975c19680ef4bfbad1a5b8939c14bd3b3e0251b15a2b0aa36dc7aba5c4ddf9ca2157e6cf54133297
@@ -0,0 +1,61 @@
1
+ require 'rest-client'
2
+ require 'securerandom'
3
+ require 'json'
4
+
5
+ class OxfordSpeechApi
6
+ def initialize(client, secret)
7
+ @client = client
8
+ @secret = secret
9
+ end
10
+
11
+ def speech2text(file, codec, rate)
12
+ params = {
13
+ :scenarios => 'ulm',
14
+ :appID => 'D4D52672-91D7-4C74-8AD8-42B1D98141A5',
15
+ :locale => 'en-US',
16
+ 'device.os' => 'Oxford Speech Client',
17
+ :version => '3.0',
18
+ :format => 'json',
19
+ :requestid => SecureRandom.uuid,
20
+ :instanceid => SecureRandom.uuid
21
+ }
22
+ data = File.read(file)
23
+ headers = {
24
+ :content_type => codec.to_s + '; samplerate=' + rate.to_s,
25
+ :content_length => data.size,
26
+ :authorization => 'Bearer ' + get_access_token
27
+ }
28
+ response = RestClient.post 'https://speech.platform.bing.com/recognize/query?' + URI.encode_www_form(params), data, headers
29
+ JSON.parse(response)
30
+ end
31
+
32
+ def text2speech(text)
33
+ headers = {
34
+ :content_type => 'application/ssml+xml',
35
+ 'X-Microsoft-OutputFormat' => 'riff-8khz-8bit-mono-mulaw',
36
+ 'X-Search-AppId' => SecureRandom.uuid.gsub(/[^0-9a-z ]/i, ''),
37
+ 'X-Search-ClientID' => SecureRandom.uuid.gsub(/[^0-9a-z ]/i, ''),
38
+ :user_agent => @client,
39
+ 'X-Search-PartnerEventID' => SecureRandom.uuid.gsub(/[^0-9a-z ]/i, ''),
40
+ :authorization => 'Bearer ' + get_access_token
41
+ }
42
+
43
+ data = "<speak version='1.0' xml:lang='en-US'><voice xml:lang='en-US' xml:gender='Female' name='Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)'>" + text + "</voice></speak>"
44
+ response = RestClient.post 'https://speech.platform.bing.com/synthesize', data, headers
45
+ end
46
+
47
+ private
48
+
49
+ def get_access_token
50
+ params = {
51
+ :grant_type => 'client_credentials',
52
+ :client_id => @client,
53
+ :client_secret => @secret,
54
+ :scope => 'https://speech.platform.bing.com'
55
+ }
56
+ response = RestClient.post 'https://oxford-speech.cloudapp.net/token/issueToken', params
57
+ json = JSON.parse(response)
58
+
59
+ json['access_token']
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oxford-speech-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Farjad Adamjee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Microsoft Oxford Speech API, Speech to Text, Text to Speech functionality
28
+ email: farjad@farjad.net
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/oxford-speech-api.rb
34
+ homepage: https://github.com/Farjad/oxford-speech-api
35
+ licenses:
36
+ - MIT
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.4.5
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Oxford Speech API
58
+ test_files: []