Class: Pocketsphinx::AudioFile
- Inherits:
-
Struct
- Object
- Struct
- Pocketsphinx::AudioFile
- Defined in:
- lib/pocketsphinx/audio_file.rb
Overview
Implements Recordable interface (#record 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.
- #record ⇒ 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.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pocketsphinx/audio_file.rb', line 17 def read_audio(buffer, max_samples = 4096) if file.nil? raise "Can't read audio: use AudioFile#record to open the file first" end if data = file.read(max_samples * 2) buffer.write_string(data) data.length / 2 end end |
#record ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/pocketsphinx/audio_file.rb', line 4 def record File.open(file_path, 'rb') do |file| self.file = file yield self.file = nil end end |