RAPP Platform API
 All Classes Namespaces Files Functions Variables Typedefs
SpeechRecognitionSphinx.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 SpeechRecognitionSphinx(CloudMsg):
12  """ Speech Recognition Sphinx4 Cloud Message object """
13 
14  class Request(CloudRequest):
15  """ Speech Recognition Sphinx4 Cloud Request object.
16  SpeechRecognitionSphinx.Request
17  """
18  def __init__(self, **kwargs):
19  """!
20  Constructor
21 
22  @param **kwargs - Keyword arguments. Apply values to the request attributes.
23  - @ref audio_source
24  - @ref audiofile
25  - @ref language
26  - @ref words
27  - @ref sentences
28  - @ref grammar
29  """
30 
31  ## Language to use for recognition
32  self.language = ''
33  ## Audio source data format. e.g "nao_wav_1_ch".
34  self.audio_source = ''
35  ## A vector that carries the words to recognize.
36  self.words = []
37  ## The under consideration sentences.
38  self.sentences = []
39  ## Grammar to use
40  self.grammar = []
41  ## Path to the audio file.
42  self.audiofile = ''
43 
44  super(SpeechRecognitionSphinx.Request, self).__init__(**kwargs)
45 
46 
47  def make_payload(self):
48  """ Create and return the Payload of the Request. """
49  return Payload(
50  language=self.language,
51  audio_source = self.audio_source,
52  words=self.words,
53  sentences=self.sentences,
54  grammar=self.grammar)
55 
56 
57  def make_files(self):
58  """ Create and return Array of File objects of the Request. """
59  return [File(self.audiofile, postfield='file')]
60 
61 
62  class Response(CloudResponse):
63  """ Speech Recognition Sphinx4 Cloud Response object.
64  SpeechRecognitionSphinx.Response
65  """
66  def __init__(self, **kwargs):
67  """!
68  Constructor
69 
70  @param **kwargs - Keyword arguments. Apply values to the request attributes.
71  - @ref error
72  - @ref words
73  """
74 
75  ## Recognized words.
76  self.words = []
77  ## Error message.
78  self.error = ''
79  super(SpeechRecognitionSphinx.Response, self).__init__(**kwargs)
80 
81 
82  def __init__(self, **kwargs):
83  """!
84  Constructor
85 
86  @param **kwargs - Keyword arguments. Apply values to the request attributes.
87  - @ref Request.audio_source
88  - @ref Request.audiofile
89  - @ref Request.language
90  - @ref Request.words
91  - @ref Request.sentences
92  - @ref Request.grammar
93  """
94 
95  # Create and hold the Request object for this CloudMsg
97  # Create and hold the Response object for this CloudMsg
99  super(SpeechRecognitionSphinx, self).__init__(
100  svcname='speech_detection_sphinx4', **kwargs)
101 
102