watsonbox/pocketsphinx-ruby

View on GitHub
examples/keyword_spotter.rb

Summary

Maintainability
A
0 mins
Test Coverage
#!/usr/bin/env ruby

require "bundler/setup"
require "pocketsphinx-ruby"

include Pocketsphinx

configuration = Configuration::KeywordSpotting.new('hello computer')
recognizer = LiveSpeechRecognizer.new(configuration)

recognizer.recognize do |speech|
  if configuration.keyword == 'hello computer'
    configuration.keyword = 'goodbye computer'
  else
    configuration.keyword = 'hello computer'
  end

  recognizer.reconfigure

  puts "You said '#{speech}'. Keyword is now '#{configuration.keyword}'"
end