Sha256: 8b0baa2ab7687fa49bac908218886eda9030a434452996c1b09b296f72191c93

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

require File.expand_path('../talks/configuration.rb', __FILE__)
require File.expand_path('../talks/hooks.rb', __FILE__)

module Talks
  class << self

    VOICES = {
      :say => %w(
        agnes albert alex bad bahh bells boing bruce bubbles cellos
        deranged fred good hysterical junior kathy pipe princess ralph
        trinoids vicki victoria whisper zarvox
      ),
      :espeak => %w(en+m1 en+m2 en+m3 en+m4 en+m5 en+m6 en+m7
        en+f1 en+f2 en+f3 en+f4 en+f5 en+f6 en+f7
      )
    }

    TYPES = [:info, :warn, :success, :error]

    attr :config

    def configure(options)
      @config = Talks::Configuration.new(options)
    end

    def voices
      VOICES
    end

    def say(message, options = {})
      type = options[:type] || :default
      case config.engine
      when 'say'
        `say -v #{say_voice(type, options)} '#{message}'`
      when 'espeak'
        `espeak -v #{say_voice(type, options)} '#{message}'`
      else
        abort "Don't know that engine now: #{config.engine}"
      end
    end

    def add_hooks(command)
      Talks::Hooks.create command
    end

    TYPES.each do |type|
      define_method type do |message = nil, options = {type: type}|
        message ||= config.message(type)
        say(message, options)
      end
    end

    private

    def say_voice(type, options)
      if options[:voice] and VOICES[config.engine.to_sym].include?(options[:voice].to_s)
        options[:voice]
      elsif TYPES.include? type
        config.voice type
      else
        config.default_voice
      end
    end

  end
end

require File.expand_path('../talks/runner.rb', __FILE__)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
talks-0.2.0 lib/talks.rb