Method and apparatus for speech recognition