lib/aia.rb in aia-0.5.15 vs lib/aia.rb in aia-0.5.16

- old
+ new

@@ -47,16 +47,10 @@ class << self attr_accessor :config attr_accessor :client def run(args=ARGV) - begin - @client = OpenAI::Client.new(access_token: ENV["OPENAI_API_KEY"]) - rescue OpenAI::ConfigurationError - @client = nil - end - args = args.split(' ') if args.is_a?(String) # TODO: Currently this is a one and done architecture. # If the args contain an "-i" or and "--interactive" # flag could this turn into some kind of @@ -70,45 +64,15 @@ return unless config.speak? if OS.osx? && 'siri' == config.voice.downcase system "say #{Shellwords.escape(what)}" else - use_openai_tts(what) + Client.speak(what) end end - def use_openai_tts(what) - if client.nil? - puts "\nWARNING: OpenAI's text to speech capability is not available at this time." - return - end - - player = if OS.osx? - 'afplay' - elsif OS.linux? - 'mpg123' - elsif OS.windows? - 'cmdmp3' - else - puts "\nWARNING: There is no MP3 player available" - return - end - - response = client.audio.speech( - parameters: { - model: config.speech_model, - input: what, - voice: config.voice - } - ) - - Tempfile.create(['speech', '.mp3']) do |f| - f.binmode - f.write(response) - f.close - `#{player} #{f.path}` - end - end + def verbose? = AIA.config.verbose? + def debug? = AIA.config.debug? end end