Sha256: c9602e2e2859069f1f883aa841a94b60688e950abc011a8845e5d9a77cace0e1

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require "azure/tts/version"

require "faraday"
require "faraday_middleware"
require "ruby_speech"

require "azure/tts/constants"
require "azure/tts/errors"
require "azure/tts/api"
require "azure/tts/configuration"
require "azure/tts/token"
require "azure/tts/speaker"
require "azure/tts/voices"

module Azure
  module TTS
    include Azure::TTS::Constants

    module_function

    def config
      @config ||= Configuration.new
    end

    def configure
      yield(config)
      reset
    end

    def voices
      @voices ||= Voices.new
    end

    def speak(text:, voice: nil, locale: nil, gender: nil, neural: nil, format: :audio_24khz_160kbitrate_mono_mp3) # rubocop:disable Metrics/ParameterLists
      voice ||= voices.find(locale: locale, gender: gender, neural: neural)
      Speaker.new(text: text, voice: voice, format: format).speak
    end

    def token
      @token ||= Token.new
      @token.tap(&:refresh)
    end

    def api
      @api ||= API.new
    end

    def reset
      @api = nil
      @voices = nil
      @token = nil
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
azure-tts-1.0.0 lib/azure/tts.rb