class SFML::SoundBufferRecorder
Records audio from the system input (microphone) directly into a SoundBuffer. Quickest path for a “record audio” feature — start, speak, stop, save:
recorder = SFML::SoundBufferRecorder.new recorder.start(sample_rate: 44100) sleep 3 recorder.stop recorder.buffer.save(“memo.wav”)
Recording requires a working input device; SFML::SoundRecorder.available? tells you whether one is present before you start.
Public Class Methods
Source
# File lib/sfml/audio/sound_buffer_recorder.rb, line 15 def initialize ptr = C::Audio.sfSoundBufferRecorder_create raise AudioError, "sfSoundBufferRecorder_create returned NULL" if ptr.null? @handle = FFI::AutoPointer.new(ptr, C::Audio.method(:sfSoundBufferRecorder_destroy)) end
Public Instance Methods
Source
# File lib/sfml/audio/sound_buffer_recorder.rb, line 52 def buffer ptr = C::Audio.sfSoundBufferRecorder_getBuffer(@handle) raise AudioError, "sfSoundBufferRecorder_getBuffer returned NULL" if ptr.null? # Borrowed — recorder owns the underlying sf::SoundBuffer. buf = SoundBuffer.allocate buf.instance_variable_set(:@handle, ptr) buf end
The captured audio so far. Returned as a borrowed SoundBuffer owned by the recorder — copy it (via save or by feeding to a Sound) before destroying the recorder, or build a Sound that outlives the recorder via the buffer’s data.
Source
# File lib/sfml/audio/sound_buffer_recorder.rb, line 39 def channel_count C::Audio.sfSoundBufferRecorder_getChannelCount(@handle) end
Returns the channel count.
Source
# File lib/sfml/audio/sound_buffer_recorder.rb, line 44 def channel_count=(value) C::Audio.sfSoundBufferRecorder_setChannelCount(@handle, Integer(value)) end
Set the channel count.
Source
# File lib/sfml/audio/sound_buffer_recorder.rb, line 62 def device name = C::Audio.sfSoundBufferRecorder_getDevice(@handle) name unless name.nil? || name.empty? end
Currently selected input device name (or nil).
Source
# File lib/sfml/audio/sound_buffer_recorder.rb, line 68 def device=(name) ok = C::Audio.sfSoundBufferRecorder_setDevice(@handle, name.to_s) raise AudioError, "could not select recording device #{name.inspect}" unless ok name end
Set the device.
Source
# File lib/sfml/audio/sound_buffer_recorder.rb, line 34 def sample_rate C::Audio.sfSoundBufferRecorder_getSampleRate(@handle) end
Returns the sample rate.
Source
# File lib/sfml/audio/sound_buffer_recorder.rb, line 23 def start(sample_rate: 44_100) C::Audio.sfSoundBufferRecorder_start(@handle, Integer(sample_rate)) end
Begin capturing samples at the given sample rate. Returns true on success, false if the device couldn’t be opened.
Source
# File lib/sfml/audio/sound_buffer_recorder.rb, line 28 def stop C::Audio.sfSoundBufferRecorder_stop(@handle) self end
Returns the stop.