adhearsion / ruby_speech

A ruby library for TTS & ASR document preparation
MIT License
101 stars 41 forks source link

NoMethodError for nil object on bad accessor #23

Closed bklang closed 10 years ago

bklang commented 10 years ago
nlsml = RubySpeech.parse <<_EOF
<result xmlns="http://www.ietf.org/xml/ns/mrcpv2" grammar="http://grammar">
  <interpretation confidence="0.63">
    <instance>
      <target>
        <string>garage door</string>
      </target>
    </instance>
  </interpretation>
</result>
_EOF

puts nlsml.interpretations.first[:instance][:action]

Yields:

<NoMethodError> undefined method `content' for nil:NilClass
    /home/vagrant/.rvm/gems/ruby-2.1.1/gems/ruby_speech-2.3.1/lib/ruby_speech/nlsml/document.rb:61:in `input_hash_for_interpretation'
    /home/vagrant/.rvm/gems/ruby-2.1.1/gems/ruby_speech-2.3.1/lib/ruby_speech/nlsml/document.rb:105:in `interpretation_hash_for_interpretation'
    /home/vagrant/.rvm/gems/ruby-2.1.1/gems/ruby_speech-2.3.1/lib/ruby_speech/nlsml/document.rb:21:in `block in interpretations'
    /home/vagrant/.rvm/gems/ruby-2.1.1/gems/ruby_speech-2.3.1/lib/ruby_speech/nlsml/document.rb:20:in `map'
    /home/vagrant/.rvm/gems/ruby-2.1.1/gems/ruby_speech-2.3.1/lib/ruby_speech/nlsml/document.rb:20:in `interpretations'
bklang commented 10 years ago

Part of the problem here is the invalid NLSML (the <string/> wrapper). Another problem is that the API for drawling NLSML is different from GRXML and SSML, leading to confusion.