15267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)/* 25267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Copyright (C) 2012 Google Inc. All rights reserved. 35267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * 45267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without 55267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * modification, are permitted provided that the following conditions 65267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * are met: 75267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * * Redistributions of source code must retain the above copyright 85267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * notice, this list of conditions and the following disclaimer. 95267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * * Redistributions in binary form must reproduce the above copyright 105267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 115267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * documentation and/or other materials provided with the distribution. 125267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * 135267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 145267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 155267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 165267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 175267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 185267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 195267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 205267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 215267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 225267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 235267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 245267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) */ 255267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 265267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#ifndef WebSpeechRecognizerClient_h 275267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#define WebSpeechRecognizerClient_h 285267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 295267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "../platform/WebVector.h" 305267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 3151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)namespace blink { 325267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 335267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebSpeechRecognitionResult; 345267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebSpeechRecognitionHandle; 355267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebString; 365267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 375267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)// A client for reporting progress on speech recognition for a specific handle. 385267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebSpeechRecognizerClient { 395267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)public: 405267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) enum ErrorCode { 415267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) OtherError = 0, 425267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) NoSpeechError = 1, 435267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) AbortedError = 2, 445267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) AudioCaptureError = 3, 455267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) NetworkError = 4, 465267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) NotAllowedError = 5, 475267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) ServiceNotAllowedError = 6, 485267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) BadGrammarError = 7, 495267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) LanguageNotSupportedError = 8 505267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) }; 515267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 525267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // These methods correspond to the events described in the spec: 535267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // http://speech-javascript-api-spec.googlecode.com/git/speechapi.html#speechreco-events 545267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 555267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // To be called when the embedder has started to capture audio. 565267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) virtual void didStartAudio(const WebSpeechRecognitionHandle&) = 0; 575267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 585267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // To be called when some sound, possibly speech, has been detected. 595267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // This is expected to be called after didStartAudio. 605267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) virtual void didStartSound(const WebSpeechRecognitionHandle&) = 0; 615267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 625267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // To be called when sound is no longer detected. 635267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // This is expected to be called after didEndSpeech. 645267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) virtual void didEndSound(const WebSpeechRecognitionHandle&) = 0; 655267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 665267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // To be called when audio capture has stopped. 675267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // This is expected to be called after didEndSound. 685267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) virtual void didEndAudio(const WebSpeechRecognitionHandle&) = 0; 695267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 705267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // To be called when the speech recognizer provides new results. 715267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // - newFinalResults contains zero or more final results that are new since 725267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // the last time the function was called. 735267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // - currentInterimResults contains zero or more inteirm results that 745267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // replace the interim results that were reported the last time this 755267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // function was called. 765267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) virtual void didReceiveResults(const WebSpeechRecognitionHandle&, const WebVector<WebSpeechRecognitionResult>& newFinalResults, const WebVector<WebSpeechRecognitionResult>& currentInterimResults) = 0; 775267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 785267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // To be called when the speech recognizer returns a final result with no 795267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // recognizion hypothesis. 805267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) virtual void didReceiveNoMatch(const WebSpeechRecognitionHandle&, const WebSpeechRecognitionResult&) = 0; 815267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 825267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // To be called when a speech recognition error occurs. 835267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) virtual void didReceiveError(const WebSpeechRecognitionHandle&, const WebString& message, ErrorCode) = 0; 845267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 855267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // To be called when the recognizer has begun to listen to the audio with 865267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // the intention of recognizing. 875267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) virtual void didStart(const WebSpeechRecognitionHandle&) = 0; 885267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 895267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // To be called when the recognition session has ended. This must always be 905267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) // called, no matter the reason for the end. 915267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) virtual void didEnd(const WebSpeechRecognitionHandle&) = 0; 925267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 935267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)protected: 945267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) virtual ~WebSpeechRecognizerClient() {} 955267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)}; 965267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 9751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} // namespace blink 985267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 995267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#endif // WebSpeechRecognizerClient_h 100