Class: AzureSTT::Client
- Inherits:
-
Object
- Object
- AzureSTT::Client
- Includes:
- HTTParty
- Defined in:
- lib/azure_stt/client.rb
Overview
Client class that uses HTTParty to communicate with the API
Instance Attribute Summary collapse
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#subscription_key ⇒ Object
readonly
Returns the value of attribute subscription_key.
Instance Method Summary collapse
-
#create_transcription(**args) ⇒ Hash
Create a transcription for a batch or a single file.
-
#get_file(file_url) ⇒ Hash
Read a JSON file and parse it.
-
#get_transcription(id) ⇒ Hash
Get a transcription by giving it's id.
-
#get_transcription_files(id) ⇒ Array[Hash]
Get an array containing the files for a given transcription.
-
#get_transcriptions(skip: nil, top: nil) ⇒ Array[Hash]
Get an Array of all the transcriptions.
-
#initialize(region:, subscription_key:) ⇒ Client
constructor
Initialize the client.
Constructor Details
#initialize(region:, subscription_key:) ⇒ Client
Initialize the client
20 21 22 23 24 |
# File 'lib/azure_stt/client.rb', line 20 def initialize(region:, subscription_key:) @subscription_key = subscription_key @region = region self.class.base_uri "https://#{region}.api.cognitive.microsoft.com/speechtotext/v3.0" end |
Instance Attribute Details
#region ⇒ Object (readonly)
Returns the value of attribute region.
12 13 14 |
# File 'lib/azure_stt/client.rb', line 12 def region @region end |
#subscription_key ⇒ Object (readonly)
Returns the value of attribute subscription_key.
12 13 14 |
# File 'lib/azure_stt/client.rb', line 12 def subscription_key @subscription_key end |
Instance Method Details
#create_transcription(**args) ⇒ Hash
Create a transcription for a batch or a single file.
35 36 37 38 39 40 41 42 |
# File 'lib/azure_stt/client.rb', line 35 def create_transcription(**args) results = post( '/transcriptions', args.to_json ) results.parsed_response end |
#get_file(file_url) ⇒ Hash
Read a JSON file and parse it.
100 101 102 103 104 105 106 |
# File 'lib/azure_stt/client.rb', line 100 def get_file(file_url) response = self.class.get(file_url) results = handle_response(response) results.parsed_response end |
#get_transcription(id) ⇒ Hash
Get a transcription by giving it's id
51 52 53 54 55 |
# File 'lib/azure_stt/client.rb', line 51 def get_transcription(id) results = get("/transcriptions/#{id}") results.parsed_response end |
#get_transcription_files(id) ⇒ Array[Hash]
Get an array containing the files for a given transcription
87 88 89 90 91 |
# File 'lib/azure_stt/client.rb', line 87 def get_transcription_files(id) results = get("/transcriptions/#{id}/files") results.parsed_response['values'] end |
#get_transcriptions(skip: nil, top: nil) ⇒ Array[Hash]
Get an Array of all the transcriptions
are Hashes parsed by HTTParty.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/azure_stt/client.rb', line 66 def get_transcriptions(skip: nil, top: nil) results = get( '/transcriptions', { skip: skip, top: top }.compact ) results.parsed_response['values'] end |