1 /* 2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef WebSpeechRecognizerClient_h 27 #define WebSpeechRecognizerClient_h 28 29 #include "../platform/WebVector.h" 30 31 namespace blink { 32 33 class WebSpeechRecognitionResult; 34 class WebSpeechRecognitionHandle; 35 class WebString; 36 37 // A client for reporting progress on speech recognition for a specific handle. 38 class WebSpeechRecognizerClient { 39 public: 40 enum ErrorCode { 41 OtherError = 0, 42 NoSpeechError = 1, 43 AbortedError = 2, 44 AudioCaptureError = 3, 45 NetworkError = 4, 46 NotAllowedError = 5, 47 ServiceNotAllowedError = 6, 48 BadGrammarError = 7, 49 LanguageNotSupportedError = 8 50 }; 51 52 // These methods correspond to the events described in the spec: 53 // http://speech-javascript-api-spec.googlecode.com/git/speechapi.html#speechreco-events 54 55 // To be called when the embedder has started to capture audio. 56 virtual void didStartAudio(const WebSpeechRecognitionHandle&) = 0; 57 58 // To be called when some sound, possibly speech, has been detected. 59 // This is expected to be called after didStartAudio. 60 virtual void didStartSound(const WebSpeechRecognitionHandle&) = 0; 61 62 // To be called when sound is no longer detected. 63 // This is expected to be called after didEndSpeech. 64 virtual void didEndSound(const WebSpeechRecognitionHandle&) = 0; 65 66 // To be called when audio capture has stopped. 67 // This is expected to be called after didEndSound. 68 virtual void didEndAudio(const WebSpeechRecognitionHandle&) = 0; 69 70 // To be called when the speech recognizer provides new results. 71 // - newFinalResults contains zero or more final results that are new since 72 // the last time the function was called. 73 // - currentInterimResults contains zero or more inteirm results that 74 // replace the interim results that were reported the last time this 75 // function was called. 76 virtual void didReceiveResults(const WebSpeechRecognitionHandle&, const WebVector<WebSpeechRecognitionResult>& newFinalResults, const WebVector<WebSpeechRecognitionResult>& currentInterimResults) = 0; 77 78 // To be called when the speech recognizer returns a final result with no 79 // recognizion hypothesis. 80 virtual void didReceiveNoMatch(const WebSpeechRecognitionHandle&, const WebSpeechRecognitionResult&) = 0; 81 82 // To be called when a speech recognition error occurs. 83 virtual void didReceiveError(const WebSpeechRecognitionHandle&, const WebString& message, ErrorCode) = 0; 84 85 // To be called when the recognizer has begun to listen to the audio with 86 // the intention of recognizing. 87 virtual void didStart(const WebSpeechRecognitionHandle&) = 0; 88 89 // To be called when the recognition session has ended. This must always be 90 // called, no matter the reason for the end. 91 virtual void didEnd(const WebSpeechRecognitionHandle&) = 0; 92 93 protected: 94 virtual ~WebSpeechRecognizerClient() {} 95 }; 96 97 } // namespace blink 98 99 #endif // WebSpeechRecognizerClient_h 100