RAPP Platform API
 All Classes Namespaces Files Functions Variables Typedefs
SpeechRecognitionGoogle.py
Go to the documentation of this file.
1 from RappCloud.Objects import (
2  File,
3  Payload)
4 
5 from Cloud import (
6  CloudMsg,
7  CloudRequest,
8  CloudResponse)
9 
10 
11 class SpeechRecognitionGoogle(CloudMsg):
12  """ Speech Recognition Google Cloud Message object """
13 
14  class Request(CloudRequest):
15  """ Speech Recognition Google Cloud Request object.
16 
17  SpeechRecognitionGoogle.Request
18  """
19  def __init__(self, **kwargs):
20  """!
21  Constructor
22 
23  @param **kwargs - Keyword arguments. Apply values to the request attributes.
24  - @ref audio_source
25  - @ref audiofile
26  - @ref language
27  """
28 
29  ## Language to use for recognition
30  self.language = ''
31  ## Audio source data format. e.g "nao_wav_1_ch".
32  self.audio_source = ''
33  ## Path to the audio file.
34  self.audiofile = ''
35 
36  super(SpeechRecognitionGoogle.Request, self).__init__(**kwargs)
37 
38 
39  def make_payload(self):
40  """ Create and return the Payload of the Request. """
41  return Payload(
42  language=self.language,
43  audio_source = self.audio_source)
44 
45 
46  def make_files(self):
47  """ Create and return Array of File objects of the Request. """
48  return [File(self.audiofile, postfield='file')]
49 
50 
51  class Response(CloudResponse):
52  """ Speech Recognition Google Cloud Response object.
53 
54  SpeechRecognitionGoogle.Response
55  """
56  def __init__(self, **kwargs):
57  """!
58  Constructor
59 
60  @param **kwargs - Keyword arguments. Apply values to the request attributes.
61  - @ref error
62  - @ref words
63  - @ref alternatives
64  """
65 
66  ## An array that contains the "words-found" with highest confidence.
67  self.words = []
68  ## Alternative sentences.
69  # e.g. [['send', 'mail'], ['send', 'email'], ['set', 'mail']...]
70  self.alternatives = []
71  ## Error message.
72  self.error = ''
73  super(SpeechRecognitionGoogle.Response, self).__init__(**kwargs)
74 
75 
76  def __init__(self, **kwargs):
77  """!
78  Constructor
79 
80  @param **kwargs - Keyword arguments. Apply values to the request attributes.
81  - @ref Request.audio_source
82  - @ref Request.audiofile
83  - @ref Request.language
84  """
85 
86  # Create and hold the Request object for this CloudMsg
88  # Create and hold the Response object for this CloudMsg
90  super(SpeechRecognitionGoogle, self).__init__(
91  svcname='speech_detection_google', **kwargs)
92 
93 
words
An array that contains the "words-found" with highest confidence.