Class: AskChatgpt::VoiceFlow::AudioRecorder
- Inherits:
-
Object
- Object
- AskChatgpt::VoiceFlow::AudioRecorder
- Defined in:
- lib/ask_chatgpt/voice.rb
Constant Summary collapse
- OUTPUT_FILE =
"output.wav"
Instance Method Summary collapse
-
#audio_device_id ⇒ Object
ffmpeg -f avfoundation -list_devices true -i “”.
- #delete_audio_file ⇒ Object
-
#initialize(duration) ⇒ AudioRecorder
constructor
A new instance of AudioRecorder.
- #start ⇒ Object
- #stop ⇒ Object
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_id ⇒ Object
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_file ⇒ Object
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 |
#start ⇒ Object
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 |
#stop ⇒ Object
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 |