Method: Pocketsphinx::Decoder#decode_raw

Defined in:
lib/pocketsphinx/decoder.rb

#decode_raw(audio_file, max_samples = 2048) ⇒ Object

Decode a raw audio stream as a single utterance.

No headers are recognized in this files. The configuration parameters samprate and input_endian are used to determine the sampling rate and endianness of the stream, respectively. Audio is always assumed to be 16-bit signed PCM.

Parameters:

  • audio_file (IO)

    The raw audio stream to decode as a single utterance

  • max_samples (Fixnum) (defaults to: 2048)

    The maximum samples to process from the stream on each iteration



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/pocketsphinx/decoder.rb', line 71

def decode_raw(audio_file, max_samples = 2048)
  start_utterance

  FFI::MemoryPointer.new(:int16, max_samples) do |buffer|
    while data = audio_file.read(max_samples * 2)
      buffer.write_string(data)
      process_raw(buffer, data.length / 2)
    end
  end

  end_utterance
end