Class: AskChatgpt::VoiceFlow::AudioRecorder

Inherits:
Object
  • Object
show all
Defined in:
lib/ask_chatgpt/voice.rb

Constant Summary collapse

OUTPUT_FILE =
"output.wav"

Instance Method Summary collapse

Constructor Details

#initialize(duration) ⇒ AudioRecorder

Returns a new instance of AudioRecorder.



26
27
28
# File 'lib/ask_chatgpt/voice.rb', line 26

def initialize(duration)
  @duration = duration
end

Instance Method Details

#audio_device_idObject

ffmpeg -f avfoundation -list_devices true -i “”



31
32
33
# File 'lib/ask_chatgpt/voice.rb', line 31

def audio_device_id
  AskChatGPT.audio_device_id
end

#delete_audio_fileObject



49
50
51
# File 'lib/ask_chatgpt/voice.rb', line 49

def delete_audio_file
  FileUtils.rm(OUTPUT_FILE) if File.exist?(OUTPUT_FILE)
end

#startObject



35
36
37
38
39
# File 'lib/ask_chatgpt/voice.rb', line 35

def start
  delete_audio_file
  ffmpeg_command = build_ffmpeg_command
  @stdin, @stdout_and_stderr, @wait_thread = Open3.popen2e(ffmpeg_command)
end

#stopObject



41
42
43
44
45
46
47
# File 'lib/ask_chatgpt/voice.rb', line 41

def stop
  @stdin.puts 'q'
  @stdin.close
  @stdout_and_stderr.close
  sleep(0.2)
rescue Errno::EPIPE, IOError
end