Class: Pocketsphinx::AudioFile
- Inherits:
-
Struct
- Object
- Struct
- Pocketsphinx::AudioFile
- Defined in:
- lib/pocketsphinx/audio_file.rb
Overview
Implements Recordable interface (#start_recording, #stop_recording and #read_audio)
Instance Attribute Summary collapse
-
#file_path ⇒ Object
Returns the value of attribute file_path.
Instance Method Summary collapse
-
#read_audio(buffer, max_samples = 4096) ⇒ Fixnum
Read next block of audio samples from file; up to max samples into buffer.
- #start_recording ⇒ Object
- #stop_recording ⇒ Object
Instance Attribute Details
#file_path ⇒ Object
Returns the value of attribute file_path
3 4 5 |
# File 'lib/pocketsphinx/audio_file.rb', line 3 def file_path @file_path end |
Instance Method Details
#read_audio(buffer, max_samples = 4096) ⇒ Fixnum
Read next block of audio samples from file; up to max samples into buffer.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/pocketsphinx/audio_file.rb', line 9 def read_audio(buffer, max_samples = 4096) if file.nil? raise "Can't read audio: use AudioFile#start_recording to open the file first" end if data = file.read(max_samples * 2) buffer.write_string(data) data.length / 2 end end |
#start_recording ⇒ Object
20 21 22 |
# File 'lib/pocketsphinx/audio_file.rb', line 20 def start_recording self.file = File.open(file_path, 'rb') end |
#stop_recording ⇒ Object
24 25 26 27 28 29 |
# File 'lib/pocketsphinx/audio_file.rb', line 24 def stop_recording if file file.close self.file = nil end end |