Sha256: 75d89d0fded61d3c8d1d51b5eeef095a0d21ab859a81e1e9533800b60caa307a
Contents?: true
Size: 1.2 KB
Versions: 1
Compression:
Stored size: 1.2 KB
Contents
# frozen_string_literal: true module Azure module TTS class API include Constants def config Azure::TTS.config end def tokens @tokens ||= Faraday.new(url: config.tokens_url, headers: { "Ocp-Apim-Subscription-Key" => config.api_key }) do |connection| connection.adapter Faraday.default_adapter end end def voices @voices ||= Faraday.new(url: config.voices_url) do |connection| connection.request :azure_tts_token_auth connection.request :json connection.response :json connection.adapter Faraday.default_adapter end end def tts @tts ||= Faraday.new(url: config.tts_url) do |connection| connection.request :azure_tts_token_auth connection.adapter Faraday.default_adapter end end end class TokenAuthMiddleware < Faraday::Middleware def initialize(app) super(app) end def call(env) env[:request_headers]["Authorization"] = "Bearer #{Azure::TTS.token}" @app.call(env) end end Faraday::Request.register_middleware azure_tts_token_auth: -> { TokenAuthMiddleware } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
azure-tts-1.0.0 | lib/azure/tts/api.rb |