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.
-
#delete_transcription(id) ⇒ Boolean
Delete a transcription with a given ID.
-
#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
19 20 21 22 23 |
# File 'lib/azure_stt/client.rb', line 19 def initialize(region:, subscription_key:) @subscription_key = subscription_key @region = region self.class.base_uri "https://#{region}.api.cognitive.microsoft.com/speechtotext/v3.1" end |
Instance Attribute Details
#region ⇒ Object (readonly)
Returns the value of attribute region.
11 12 13 |
# File 'lib/azure_stt/client.rb', line 11 def region @region end |
#subscription_key ⇒ Object (readonly)
Returns the value of attribute subscription_key.
11 12 13 |
# File 'lib/azure_stt/client.rb', line 11 def subscription_key @subscription_key end |
Instance Method Details
#create_transcription(**args) ⇒ Hash
Create a transcription for a batch or a single file.
34 35 36 37 38 39 40 41 |
# File 'lib/azure_stt/client.rb', line 34 def create_transcription(**args) results = post( '/transcriptions', args.to_json ) results.parsed_response end |
#delete_transcription(id) ⇒ Boolean
Delete a transcription with a given ID
84 85 86 87 88 89 |
# File 'lib/azure_stt/client.rb', line 84 def delete_transcription(id) response = self.class.delete("/transcriptions/#{id}", headers: headers) handle_response(response) true end |
#get_file(file_url) ⇒ Hash
Read a JSON file and parse it.
113 114 115 116 117 118 119 |
# File 'lib/azure_stt/client.rb', line 113 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
50 51 52 53 54 |
# File 'lib/azure_stt/client.rb', line 50 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
100 101 102 103 104 |
# File 'lib/azure_stt/client.rb', line 100 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.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/azure_stt/client.rb', line 65 def get_transcriptions(skip: nil, top: nil) results = get( '/transcriptions', { skip: skip, top: top }.compact ) results.parsed_response['values'] end |