We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Client library incorrectly returns error when FLAC is used with long-running-recognize
The client library incorrectly returns an error when anything other than LINEAR16 is used for a long-running recognize request:

[https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/speech/google/cloud/speech/sample.py#L173][1]

The v1 server support all encodings so this breaks functionality.

In general, the client library should almost never do it's own validation; it should always delegate to the server to be sure that that behavior and error messages are consistent across APIs.

[1]: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/46e417e838001f4d1eb13f5e3fc2a54d390dd5db/speech/google/cloud/speech/sample.py#L173

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `speech/google/cloud/speech/sample.py`
Content:
```
1 # Copyright 2016 Google Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 """Sample class to handle content for Google Cloud Speech API."""
16 
17 from google.cloud.speech.encoding import Encoding
18 from google.cloud.speech.result import StreamingSpeechResult
19 
20 
21 class Sample(object):
22     """Representation of an audio sample to be used with Google Speech API.
23 
24     :type content: bytes
25     :param content: (Optional) Bytes containing audio data.
26 
27     :type source_uri: str
28     :param source_uri: (Optional) URI that points to a file that contains
29                        audio data bytes as specified in RecognitionConfig.
30                        Currently, only Google Cloud Storage URIs are
31                        supported, which must be specified in the following
32                        format: ``gs://bucket_name/object_name``.
33 
34     :type stream: file
35     :param stream: (Optional) File like object to stream.
36 
37     :type encoding: str
38     :param encoding: encoding of audio data sent in all RecognitionAudio
39                      messages, can be one of: :attr:`~.Encoding.LINEAR16`,
40                      :attr:`~.Encoding.FLAC`, :attr:`~.Encoding.MULAW`,
41                      :attr:`~.Encoding.AMR`, :attr:`~.Encoding.AMR_WB`
42 
43     :type sample_rate_hertz: int
44     :param sample_rate_hertz: Sample rate in Hertz of the audio data sent in
45                               all requests. Valid values are: 8000-48000. For
46                               best results, set the sampling rate of the audio
47                               source to 16000 Hz. If that's not possible, use
48                               the native sample rate of the audio source
49                               (instead of re-sampling).
50 
51     :type client: :class:`~google.cloud.speech.client.Client`
52     :param client: (Optional) The client that owns this instance of sample.
53     """
54     default_encoding = Encoding.FLAC
55 
56     def __init__(self, content=None, source_uri=None, stream=None,
57                  encoding=None, sample_rate_hertz=None, client=None):
58         self._client = client
59 
60         sources = [content is not None, source_uri is not None,
61                    stream is not None]
62         if sources.count(True) != 1:
63             raise ValueError('Supply exactly one of '
64                              '\'content\',  \'source_uri\', \'stream\'')
65 
66         self._content = content
67         self._source_uri = source_uri
68         self._stream = stream
69 
70         if (sample_rate_hertz is not None and
71                 not 8000 <= sample_rate_hertz <= 48000):
72             raise ValueError('The value of sample_rate_hertz must be between '
73                              '8000 and 48000.')
74         self._sample_rate_hertz = sample_rate_hertz
75 
76         if encoding is not None and getattr(Encoding, encoding, False):
77             self._encoding = getattr(Encoding, encoding)
78         else:
79             raise ValueError('Invalid encoding: %s' % (encoding,))
80 
81     @property
82     def chunk_size(self):
83         """Chunk size to send over gRPC. ~100ms
84 
85         :rtype: int
86         :returns: Optimized chunk size.
87         """
88         return int(self.sample_rate_hertz / 10.0)
89 
90     @property
91     def source_uri(self):
92         """Google Cloud Storage URI of audio source.
93 
94         :rtype: str
95         :returns: Google Cloud Storage URI string.
96         """
97         return self._source_uri
98 
99     @property
100     def content(self):
101         """Bytes of audio content.
102 
103         :rtype: bytes
104         :returns: Byte stream of audio content.
105         """
106         return self._content
107 
108     @property
109     def sample_rate_hertz(self):
110         """Sample rate integer.
111 
112         :rtype: int
113         :returns: Integer between 8000 and 48,000.
114         """
115         return self._sample_rate_hertz
116 
117     @property
118     def stream(self):
119         """Stream the content when it is a file-like object.
120 
121         :rtype: file
122         :returns: File like object to stream.
123         """
124         return self._stream
125 
126     @property
127     def encoding(self):
128         """Audio encoding type
129 
130         :rtype: str
131         :returns: String value of Encoding type.
132         """
133         return self._encoding
134 
135     def long_running_recognize(self, language_code, max_alternatives=None,
136                                profanity_filter=None, speech_contexts=()):
137         """Asychronous Recognize request to Google Speech API.
138 
139         .. _long_running_recognize: https://cloud.google.com/speech/reference/\
140                                     rest/v1/speech/longrunningrecognize
141 
142         See `long_running_recognize`_.
143 
144         :type language_code: str
145         :param language_code: (Optional) The language of the supplied audio as
146                               BCP-47 language tag. Example: ``'en-US'``.
147 
148         :type max_alternatives: int
149         :param max_alternatives: (Optional) Maximum number of recognition
150                                  hypotheses to be returned. The server may
151                                  return fewer than maxAlternatives.
152                                  Valid values are 0-30. A value of 0 or 1
153                                  will return a maximum of 1. Defaults to 1
154 
155         :type profanity_filter: bool
156         :param profanity_filter: If True, the server will attempt to filter
157                                  out profanities, replacing all but the
158                                  initial character in each filtered word with
159                                  asterisks, e.g. ``'f***'``. If False or
160                                  omitted, profanities won't be filtered out.
161 
162         :type speech_contexts: list
163         :param speech_contexts: A list of strings (max 50) containing words and
164                                 phrases "hints" so that the speech recognition
165                                 is more likely to recognize them. This can be
166                                 used to improve the accuracy for specific words
167                                 and phrases. This can also be used to add new
168                                 words to the vocabulary of the recognizer.
169 
170         :rtype: :class:`~google.cloud.speech.operation.Operation`
171         :returns: Operation for asynchronous request to Google Speech API.
172         """
173         if self.encoding is not Encoding.LINEAR16:
174             raise ValueError('Only LINEAR16 encoding is supported by '
175                              'long-running speech requests.')
176         api = self._client.speech_api
177         return api.long_running_recognize(
178             self, language_code, max_alternatives, profanity_filter,
179             speech_contexts)
180 
181     def streaming_recognize(self, language_code,
182                             max_alternatives=None, profanity_filter=None,
183                             speech_contexts=(), single_utterance=False,
184                             interim_results=False):
185         """Streaming speech recognition.
186 
187         .. note::
188 
189             Streaming recognition requests are limited to 1 minute of audio.
190             See: https://cloud.google.com/speech/limits#content
191 
192         Yields: Instance of
193                 :class:`~google.cloud.speech.result.StreamingSpeechResult`
194                 containing results and metadata from the streaming request.
195 
196         :type language_code: str
197         :param language_code: The language of the supplied audio as
198                               BCP-47 language tag. Example: ``'en-US'``.
199 
200         :type max_alternatives: int
201         :param max_alternatives: (Optional) Maximum number of recognition
202                                  hypotheses to be returned. The server may
203                                  return fewer than maxAlternatives.
204                                  Valid values are 0-30. A value of 0 or 1
205                                  will return a maximum of 1. Defaults to 1
206 
207         :type profanity_filter: bool
208         :param profanity_filter: If True, the server will attempt to filter
209                                  out profanities, replacing all but the
210                                  initial character in each filtered word with
211                                  asterisks, e.g. ``'f***'``. If False or
212                                  omitted, profanities won't be filtered out.
213 
214         :type speech_contexts: list
215         :param speech_contexts: A list of strings (max 50) containing words and
216                                 phrases "hints" so that the speech recognition
217                                 is more likely to recognize them. This can be
218                                 used to improve the accuracy for specific words
219                                 and phrases. This can also be used to add new
220                                 words to the vocabulary of the recognizer.
221 
222         :type single_utterance: bool
223         :param single_utterance: (Optional) If false or omitted, the recognizer
224                                  will perform continuous recognition
225                                  (continuing to process audio even if the user
226                                  pauses speaking) until the client closes the
227                                  output stream (gRPC API) or when the maximum
228                                  time limit has been reached. Multiple
229                                  SpeechRecognitionResults with the is_final
230                                  flag set to true may be returned.
231                                  If true, the recognizer will detect a single
232                                  spoken utterance. When it detects that the
233                                  user has paused or stopped speaking, it will
234                                  return an END_OF_UTTERANCE event and cease
235                                  recognition. It will return no more than one
236                                  SpeechRecognitionResult with the is_final flag
237                                  set to true.
238 
239         :type interim_results: bool
240         :param interim_results: (Optional) If true, interim results (tentative
241                                 hypotheses) may be returned as they become
242                                 available (these interim results are indicated
243                                 with the ``is_final=False`` flag). If false or
244                                 omitted, only is_final=true result(s) are
245                                 returned.
246 
247         :raises: EnvironmentError if gRPC is not available.
248         """
249         if not self._client._use_grpc:
250             raise EnvironmentError('gRPC is required to use this API.')
251 
252         api = self._client.speech_api
253         responses = api.streaming_recognize(self, language_code,
254                                             max_alternatives, profanity_filter,
255                                             speech_contexts, single_utterance,
256                                             interim_results)
257         for response in responses:
258             for result in response.results:
259                 if result.is_final or interim_results:
260                     yield StreamingSpeechResult.from_pb(result)
261 
262     def recognize(self, language_code, max_alternatives=None,
263                   profanity_filter=None, speech_contexts=()):
264         """Synchronous Speech Recognition.
265 
266         .. _recognize: https://cloud.google.com/speech/reference/\
267                        rest/v1/speech/recognize
268 
269         See `recognize`_.
270 
271         :type language_code: str
272         :param language_code: The language of the supplied audio as
273                               BCP-47 language tag. Example: ``'en-US'``.
274 
275         :type max_alternatives: int
276         :param max_alternatives: (Optional) Maximum number of recognition
277                                  hypotheses to be returned. The server may
278                                  return fewer than maxAlternatives.
279                                  Valid values are 0-30. A value of 0 or 1
280                                  will return a maximum of 1. Defaults to 1
281 
282         :type profanity_filter: bool
283         :param profanity_filter: If True, the server will attempt to filter
284                                  out profanities, replacing all but the
285                                  initial character in each filtered word with
286                                  asterisks, e.g. ``'f***'``. If False or
287                                  omitted, profanities won't be filtered out.
288 
289         :type speech_contexts: list
290         :param speech_contexts: A list of strings (max 50) containing words and
291                                 phrases "hints" so that the speech recognition
292                                 is more likely to recognize them. This can be
293                                 used to improve the accuracy for specific words
294                                 and phrases. This can also be used to add new
295                                 words to the vocabulary of the recognizer.
296 
297         :rtype: list
298         :returns: A list of dictionaries. One dict for each alternative. Each
299                   dictionary typically contains two keys (though not
300                   all will be present in all cases)
301 
302                   * ``transcript``: The detected text from the audio recording.
303                   * ``confidence``: The confidence in language detection, float
304                     between 0 and 1.
305         """
306         api = self._client.speech_api
307         return api.recognize(self, language_code, max_alternatives,
308                              profanity_filter, speech_contexts)
309
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/speech/google/cloud/speech/sample.py b/speech/google/cloud/speech/sample.py
--- a/speech/google/cloud/speech/sample.py
+++ b/speech/google/cloud/speech/sample.py
@@ -170,9 +170,6 @@
         :rtype: :class:`~google.cloud.speech.operation.Operation`
         :returns: Operation for asynchronous request to Google Speech API.
         """
-        if self.encoding is not Encoding.LINEAR16:
-            raise ValueError('Only LINEAR16 encoding is supported by '
-                             'long-running speech requests.')
         api = self._client.speech_api
         return api.long_running_recognize(
             self, language_code, max_alternatives, profanity_filter,

{"golden_diff": "diff --git a/speech/google/cloud/speech/sample.py b/speech/google/cloud/speech/sample.py\n--- a/speech/google/cloud/speech/sample.py\n+++ b/speech/google/cloud/speech/sample.py\n@@ -170,9 +170,6 @@\n         :rtype: :class:`~google.cloud.speech.operation.Operation`\n         :returns: Operation for asynchronous request to Google Speech API.\n         \"\"\"\n-        if self.encoding is not Encoding.LINEAR16:\n-            raise ValueError('Only LINEAR16 encoding is supported by '\n-                             'long-running speech requests.')\n         api = self._client.speech_api\n         return api.long_running_recognize(\n             self, language_code, max_alternatives, profanity_filter,\n", "issue": "Client library incorrectly returns error when FLAC is used with long-running-recognize\nThe client library incorrectly returns an error when anything other than LINEAR16 is used for a long-running recognize request:\r\n\r\n[https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/speech/google/cloud/speech/sample.py#L173][1]\r\n\r\nThe v1 server support all encodings so this breaks functionality.\r\n\r\nIn general, the client library should almost never do it's own validation; it should always delegate to the server to be sure that that behavior and error messages are consistent across APIs.\r\n\r\n[1]: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/46e417e838001f4d1eb13f5e3fc2a54d390dd5db/speech/google/cloud/speech/sample.py#L173\n", "before_files": [{"content": "# Copyright 2016 Google Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Sample class to handle content for Google Cloud Speech API.\"\"\"\n\nfrom google.cloud.speech.encoding import Encoding\nfrom google.cloud.speech.result import StreamingSpeechResult\n\n\nclass Sample(object):\n    \"\"\"Representation of an audio sample to be used with Google Speech API.\n\n    :type content: bytes\n    :param content: (Optional) Bytes containing audio data.\n\n    :type source_uri: str\n    :param source_uri: (Optional) URI that points to a file that contains\n                       audio data bytes as specified in RecognitionConfig.\n                       Currently, only Google Cloud Storage URIs are\n                       supported, which must be specified in the following\n                       format: ``gs://bucket_name/object_name``.\n\n    :type stream: file\n    :param stream: (Optional) File like object to stream.\n\n    :type encoding: str\n    :param encoding: encoding of audio data sent in all RecognitionAudio\n                     messages, can be one of: :attr:`~.Encoding.LINEAR16`,\n                     :attr:`~.Encoding.FLAC`, :attr:`~.Encoding.MULAW`,\n                     :attr:`~.Encoding.AMR`, :attr:`~.Encoding.AMR_WB`\n\n    :type sample_rate_hertz: int\n    :param sample_rate_hertz: Sample rate in Hertz of the audio data sent in\n                              all requests. Valid values are: 8000-48000. For\n                              best results, set the sampling rate of the audio\n                              source to 16000 Hz. If that's not possible, use\n                              the native sample rate of the audio source\n                              (instead of re-sampling).\n\n    :type client: :class:`~google.cloud.speech.client.Client`\n    :param client: (Optional) The client that owns this instance of sample.\n    \"\"\"\n    default_encoding = Encoding.FLAC\n\n    def __init__(self, content=None, source_uri=None, stream=None,\n                 encoding=None, sample_rate_hertz=None, client=None):\n        self._client = client\n\n        sources = [content is not None, source_uri is not None,\n                   stream is not None]\n        if sources.count(True) != 1:\n            raise ValueError('Supply exactly one of '\n                             '\\'content\\',  \\'source_uri\\', \\'stream\\'')\n\n        self._content = content\n        self._source_uri = source_uri\n        self._stream = stream\n\n        if (sample_rate_hertz is not None and\n                not 8000 <= sample_rate_hertz <= 48000):\n            raise ValueError('The value of sample_rate_hertz must be between '\n                             '8000 and 48000.')\n        self._sample_rate_hertz = sample_rate_hertz\n\n        if encoding is not None and getattr(Encoding, encoding, False):\n            self._encoding = getattr(Encoding, encoding)\n        else:\n            raise ValueError('Invalid encoding: %s' % (encoding,))\n\n    @property\n    def chunk_size(self):\n        \"\"\"Chunk size to send over gRPC. ~100ms\n\n        :rtype: int\n        :returns: Optimized chunk size.\n        \"\"\"\n        return int(self.sample_rate_hertz / 10.0)\n\n    @property\n    def source_uri(self):\n        \"\"\"Google Cloud Storage URI of audio source.\n\n        :rtype: str\n        :returns: Google Cloud Storage URI string.\n        \"\"\"\n        return self._source_uri\n\n    @property\n    def content(self):\n        \"\"\"Bytes of audio content.\n\n        :rtype: bytes\n        :returns: Byte stream of audio content.\n        \"\"\"\n        return self._content\n\n    @property\n    def sample_rate_hertz(self):\n        \"\"\"Sample rate integer.\n\n        :rtype: int\n        :returns: Integer between 8000 and 48,000.\n        \"\"\"\n        return self._sample_rate_hertz\n\n    @property\n    def stream(self):\n        \"\"\"Stream the content when it is a file-like object.\n\n        :rtype: file\n        :returns: File like object to stream.\n        \"\"\"\n        return self._stream\n\n    @property\n    def encoding(self):\n        \"\"\"Audio encoding type\n\n        :rtype: str\n        :returns: String value of Encoding type.\n        \"\"\"\n        return self._encoding\n\n    def long_running_recognize(self, language_code, max_alternatives=None,\n                               profanity_filter=None, speech_contexts=()):\n        \"\"\"Asychronous Recognize request to Google Speech API.\n\n        .. _long_running_recognize: https://cloud.google.com/speech/reference/\\\n                                    rest/v1/speech/longrunningrecognize\n\n        See `long_running_recognize`_.\n\n        :type language_code: str\n        :param language_code: (Optional) The language of the supplied audio as\n                              BCP-47 language tag. Example: ``'en-US'``.\n\n        :type max_alternatives: int\n        :param max_alternatives: (Optional) Maximum number of recognition\n                                 hypotheses to be returned. The server may\n                                 return fewer than maxAlternatives.\n                                 Valid values are 0-30. A value of 0 or 1\n                                 will return a maximum of 1. Defaults to 1\n\n        :type profanity_filter: bool\n        :param profanity_filter: If True, the server will attempt to filter\n                                 out profanities, replacing all but the\n                                 initial character in each filtered word with\n                                 asterisks, e.g. ``'f***'``. If False or\n                                 omitted, profanities won't be filtered out.\n\n        :type speech_contexts: list\n        :param speech_contexts: A list of strings (max 50) containing words and\n                                phrases \"hints\" so that the speech recognition\n                                is more likely to recognize them. This can be\n                                used to improve the accuracy for specific words\n                                and phrases. This can also be used to add new\n                                words to the vocabulary of the recognizer.\n\n        :rtype: :class:`~google.cloud.speech.operation.Operation`\n        :returns: Operation for asynchronous request to Google Speech API.\n        \"\"\"\n        if self.encoding is not Encoding.LINEAR16:\n            raise ValueError('Only LINEAR16 encoding is supported by '\n                             'long-running speech requests.')\n        api = self._client.speech_api\n        return api.long_running_recognize(\n            self, language_code, max_alternatives, profanity_filter,\n            speech_contexts)\n\n    def streaming_recognize(self, language_code,\n                            max_alternatives=None, profanity_filter=None,\n                            speech_contexts=(), single_utterance=False,\n                            interim_results=False):\n        \"\"\"Streaming speech recognition.\n\n        .. note::\n\n            Streaming recognition requests are limited to 1 minute of audio.\n            See: https://cloud.google.com/speech/limits#content\n\n        Yields: Instance of\n                :class:`~google.cloud.speech.result.StreamingSpeechResult`\n                containing results and metadata from the streaming request.\n\n        :type language_code: str\n        :param language_code: The language of the supplied audio as\n                              BCP-47 language tag. Example: ``'en-US'``.\n\n        :type max_alternatives: int\n        :param max_alternatives: (Optional) Maximum number of recognition\n                                 hypotheses to be returned. The server may\n                                 return fewer than maxAlternatives.\n                                 Valid values are 0-30. A value of 0 or 1\n                                 will return a maximum of 1. Defaults to 1\n\n        :type profanity_filter: bool\n        :param profanity_filter: If True, the server will attempt to filter\n                                 out profanities, replacing all but the\n                                 initial character in each filtered word with\n                                 asterisks, e.g. ``'f***'``. If False or\n                                 omitted, profanities won't be filtered out.\n\n        :type speech_contexts: list\n        :param speech_contexts: A list of strings (max 50) containing words and\n                                phrases \"hints\" so that the speech recognition\n                                is more likely to recognize them. This can be\n                                used to improve the accuracy for specific words\n                                and phrases. This can also be used to add new\n                                words to the vocabulary of the recognizer.\n\n        :type single_utterance: bool\n        :param single_utterance: (Optional) If false or omitted, the recognizer\n                                 will perform continuous recognition\n                                 (continuing to process audio even if the user\n                                 pauses speaking) until the client closes the\n                                 output stream (gRPC API) or when the maximum\n                                 time limit has been reached. Multiple\n                                 SpeechRecognitionResults with the is_final\n                                 flag set to true may be returned.\n                                 If true, the recognizer will detect a single\n                                 spoken utterance. When it detects that the\n                                 user has paused or stopped speaking, it will\n                                 return an END_OF_UTTERANCE event and cease\n                                 recognition. It will return no more than one\n                                 SpeechRecognitionResult with the is_final flag\n                                 set to true.\n\n        :type interim_results: bool\n        :param interim_results: (Optional) If true, interim results (tentative\n                                hypotheses) may be returned as they become\n                                available (these interim results are indicated\n                                with the ``is_final=False`` flag). If false or\n                                omitted, only is_final=true result(s) are\n                                returned.\n\n        :raises: EnvironmentError if gRPC is not available.\n        \"\"\"\n        if not self._client._use_grpc:\n            raise EnvironmentError('gRPC is required to use this API.')\n\n        api = self._client.speech_api\n        responses = api.streaming_recognize(self, language_code,\n                                            max_alternatives, profanity_filter,\n                                            speech_contexts, single_utterance,\n                                            interim_results)\n        for response in responses:\n            for result in response.results:\n                if result.is_final or interim_results:\n                    yield StreamingSpeechResult.from_pb(result)\n\n    def recognize(self, language_code, max_alternatives=None,\n                  profanity_filter=None, speech_contexts=()):\n        \"\"\"Synchronous Speech Recognition.\n\n        .. _recognize: https://cloud.google.com/speech/reference/\\\n                       rest/v1/speech/recognize\n\n        See `recognize`_.\n\n        :type language_code: str\n        :param language_code: The language of the supplied audio as\n                              BCP-47 language tag. Example: ``'en-US'``.\n\n        :type max_alternatives: int\n        :param max_alternatives: (Optional) Maximum number of recognition\n                                 hypotheses to be returned. The server may\n                                 return fewer than maxAlternatives.\n                                 Valid values are 0-30. A value of 0 or 1\n                                 will return a maximum of 1. Defaults to 1\n\n        :type profanity_filter: bool\n        :param profanity_filter: If True, the server will attempt to filter\n                                 out profanities, replacing all but the\n                                 initial character in each filtered word with\n                                 asterisks, e.g. ``'f***'``. If False or\n                                 omitted, profanities won't be filtered out.\n\n        :type speech_contexts: list\n        :param speech_contexts: A list of strings (max 50) containing words and\n                                phrases \"hints\" so that the speech recognition\n                                is more likely to recognize them. This can be\n                                used to improve the accuracy for specific words\n                                and phrases. This can also be used to add new\n                                words to the vocabulary of the recognizer.\n\n        :rtype: list\n        :returns: A list of dictionaries. One dict for each alternative. Each\n                  dictionary typically contains two keys (though not\n                  all will be present in all cases)\n\n                  * ``transcript``: The detected text from the audio recording.\n                  * ``confidence``: The confidence in language detection, float\n                    between 0 and 1.\n        \"\"\"\n        api = self._client.speech_api\n        return api.recognize(self, language_code, max_alternatives,\n                             profanity_filter, speech_contexts)\n", "path": "speech/google/cloud/speech/sample.py"}], "after_files": [{"content": "# Copyright 2016 Google Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Sample class to handle content for Google Cloud Speech API.\"\"\"\n\nfrom google.cloud.speech.encoding import Encoding\nfrom google.cloud.speech.result import StreamingSpeechResult\n\n\nclass Sample(object):\n    \"\"\"Representation of an audio sample to be used with Google Speech API.\n\n    :type content: bytes\n    :param content: (Optional) Bytes containing audio data.\n\n    :type source_uri: str\n    :param source_uri: (Optional) URI that points to a file that contains\n                       audio data bytes as specified in RecognitionConfig.\n                       Currently, only Google Cloud Storage URIs are\n                       supported, which must be specified in the following\n                       format: ``gs://bucket_name/object_name``.\n\n    :type stream: file\n    :param stream: (Optional) File like object to stream.\n\n    :type encoding: str\n    :param encoding: encoding of audio data sent in all RecognitionAudio\n                     messages, can be one of: :attr:`~.Encoding.LINEAR16`,\n                     :attr:`~.Encoding.FLAC`, :attr:`~.Encoding.MULAW`,\n                     :attr:`~.Encoding.AMR`, :attr:`~.Encoding.AMR_WB`\n\n    :type sample_rate_hertz: int\n    :param sample_rate_hertz: Sample rate in Hertz of the audio data sent in\n                              all requests. Valid values are: 8000-48000. For\n                              best results, set the sampling rate of the audio\n                              source to 16000 Hz. If that's not possible, use\n                              the native sample rate of the audio source\n                              (instead of re-sampling).\n\n    :type client: :class:`~google.cloud.speech.client.Client`\n    :param client: (Optional) The client that owns this instance of sample.\n    \"\"\"\n    default_encoding = Encoding.FLAC\n\n    def __init__(self, content=None, source_uri=None, stream=None,\n                 encoding=None, sample_rate_hertz=None, client=None):\n        self._client = client\n\n        sources = [content is not None, source_uri is not None,\n                   stream is not None]\n        if sources.count(True) != 1:\n            raise ValueError('Supply exactly one of '\n                             '\\'content\\',  \\'source_uri\\', \\'stream\\'')\n\n        self._content = content\n        self._source_uri = source_uri\n        self._stream = stream\n\n        if (sample_rate_hertz is not None and\n                not 8000 <= sample_rate_hertz <= 48000):\n            raise ValueError('The value of sample_rate_hertz must be between '\n                             '8000 and 48000.')\n        self._sample_rate_hertz = sample_rate_hertz\n\n        if encoding is not None and getattr(Encoding, encoding, False):\n            self._encoding = getattr(Encoding, encoding)\n        else:\n            raise ValueError('Invalid encoding: %s' % (encoding,))\n\n    @property\n    def chunk_size(self):\n        \"\"\"Chunk size to send over gRPC. ~100ms\n\n        :rtype: int\n        :returns: Optimized chunk size.\n        \"\"\"\n        return int(self.sample_rate_hertz / 10.0)\n\n    @property\n    def source_uri(self):\n        \"\"\"Google Cloud Storage URI of audio source.\n\n        :rtype: str\n        :returns: Google Cloud Storage URI string.\n        \"\"\"\n        return self._source_uri\n\n    @property\n    def content(self):\n        \"\"\"Bytes of audio content.\n\n        :rtype: bytes\n        :returns: Byte stream of audio content.\n        \"\"\"\n        return self._content\n\n    @property\n    def sample_rate_hertz(self):\n        \"\"\"Sample rate integer.\n\n        :rtype: int\n        :returns: Integer between 8000 and 48,000.\n        \"\"\"\n        return self._sample_rate_hertz\n\n    @property\n    def stream(self):\n        \"\"\"Stream the content when it is a file-like object.\n\n        :rtype: file\n        :returns: File like object to stream.\n        \"\"\"\n        return self._stream\n\n    @property\n    def encoding(self):\n        \"\"\"Audio encoding type\n\n        :rtype: str\n        :returns: String value of Encoding type.\n        \"\"\"\n        return self._encoding\n\n    def long_running_recognize(self, language_code, max_alternatives=None,\n                               profanity_filter=None, speech_contexts=()):\n        \"\"\"Asychronous Recognize request to Google Speech API.\n\n        .. _long_running_recognize: https://cloud.google.com/speech/reference/\\\n                                    rest/v1/speech/longrunningrecognize\n\n        See `long_running_recognize`_.\n\n        :type language_code: str\n        :param language_code: (Optional) The language of the supplied audio as\n                              BCP-47 language tag. Example: ``'en-US'``.\n\n        :type max_alternatives: int\n        :param max_alternatives: (Optional) Maximum number of recognition\n                                 hypotheses to be returned. The server may\n                                 return fewer than maxAlternatives.\n                                 Valid values are 0-30. A value of 0 or 1\n                                 will return a maximum of 1. Defaults to 1\n\n        :type profanity_filter: bool\n        :param profanity_filter: If True, the server will attempt to filter\n                                 out profanities, replacing all but the\n                                 initial character in each filtered word with\n                                 asterisks, e.g. ``'f***'``. If False or\n                                 omitted, profanities won't be filtered out.\n\n        :type speech_contexts: list\n        :param speech_contexts: A list of strings (max 50) containing words and\n                                phrases \"hints\" so that the speech recognition\n                                is more likely to recognize them. This can be\n                                used to improve the accuracy for specific words\n                                and phrases. This can also be used to add new\n                                words to the vocabulary of the recognizer.\n\n        :rtype: :class:`~google.cloud.speech.operation.Operation`\n        :returns: Operation for asynchronous request to Google Speech API.\n        \"\"\"\n        api = self._client.speech_api\n        return api.long_running_recognize(\n            self, language_code, max_alternatives, profanity_filter,\n            speech_contexts)\n\n    def streaming_recognize(self, language_code,\n                            max_alternatives=None, profanity_filter=None,\n                            speech_contexts=(), single_utterance=False,\n                            interim_results=False):\n        \"\"\"Streaming speech recognition.\n\n        .. note::\n\n            Streaming recognition requests are limited to 1 minute of audio.\n            See: https://cloud.google.com/speech/limits#content\n\n        Yields: Instance of\n                :class:`~google.cloud.speech.result.StreamingSpeechResult`\n                containing results and metadata from the streaming request.\n\n        :type language_code: str\n        :param language_code: The language of the supplied audio as\n                              BCP-47 language tag. Example: ``'en-US'``.\n\n        :type max_alternatives: int\n        :param max_alternatives: (Optional) Maximum number of recognition\n                                 hypotheses to be returned. The server may\n                                 return fewer than maxAlternatives.\n                                 Valid values are 0-30. A value of 0 or 1\n                                 will return a maximum of 1. Defaults to 1\n\n        :type profanity_filter: bool\n        :param profanity_filter: If True, the server will attempt to filter\n                                 out profanities, replacing all but the\n                                 initial character in each filtered word with\n                                 asterisks, e.g. ``'f***'``. If False or\n                                 omitted, profanities won't be filtered out.\n\n        :type speech_contexts: list\n        :param speech_contexts: A list of strings (max 50) containing words and\n                                phrases \"hints\" so that the speech recognition\n                                is more likely to recognize them. This can be\n                                used to improve the accuracy for specific words\n                                and phrases. This can also be used to add new\n                                words to the vocabulary of the recognizer.\n\n        :type single_utterance: bool\n        :param single_utterance: (Optional) If false or omitted, the recognizer\n                                 will perform continuous recognition\n                                 (continuing to process audio even if the user\n                                 pauses speaking) until the client closes the\n                                 output stream (gRPC API) or when the maximum\n                                 time limit has been reached. Multiple\n                                 SpeechRecognitionResults with the is_final\n                                 flag set to true may be returned.\n                                 If true, the recognizer will detect a single\n                                 spoken utterance. When it detects that the\n                                 user has paused or stopped speaking, it will\n                                 return an END_OF_UTTERANCE event and cease\n                                 recognition. It will return no more than one\n                                 SpeechRecognitionResult with the is_final flag\n                                 set to true.\n\n        :type interim_results: bool\n        :param interim_results: (Optional) If true, interim results (tentative\n                                hypotheses) may be returned as they become\n                                available (these interim results are indicated\n                                with the ``is_final=False`` flag). If false or\n                                omitted, only is_final=true result(s) are\n                                returned.\n\n        :raises: EnvironmentError if gRPC is not available.\n        \"\"\"\n        if not self._client._use_grpc:\n            raise EnvironmentError('gRPC is required to use this API.')\n\n        api = self._client.speech_api\n        responses = api.streaming_recognize(self, language_code,\n                                            max_alternatives, profanity_filter,\n                                            speech_contexts, single_utterance,\n                                            interim_results)\n        for response in responses:\n            for result in response.results:\n                if result.is_final or interim_results:\n                    yield StreamingSpeechResult.from_pb(result)\n\n    def recognize(self, language_code, max_alternatives=None,\n                  profanity_filter=None, speech_contexts=()):\n        \"\"\"Synchronous Speech Recognition.\n\n        .. _recognize: https://cloud.google.com/speech/reference/\\\n                       rest/v1/speech/recognize\n\n        See `recognize`_.\n\n        :type language_code: str\n        :param language_code: The language of the supplied audio as\n                              BCP-47 language tag. Example: ``'en-US'``.\n\n        :type max_alternatives: int\n        :param max_alternatives: (Optional) Maximum number of recognition\n                                 hypotheses to be returned. The server may\n                                 return fewer than maxAlternatives.\n                                 Valid values are 0-30. A value of 0 or 1\n                                 will return a maximum of 1. Defaults to 1\n\n        :type profanity_filter: bool\n        :param profanity_filter: If True, the server will attempt to filter\n                                 out profanities, replacing all but the\n                                 initial character in each filtered word with\n                                 asterisks, e.g. ``'f***'``. If False or\n                                 omitted, profanities won't be filtered out.\n\n        :type speech_contexts: list\n        :param speech_contexts: A list of strings (max 50) containing words and\n                                phrases \"hints\" so that the speech recognition\n                                is more likely to recognize them. This can be\n                                used to improve the accuracy for specific words\n                                and phrases. This can also be used to add new\n                                words to the vocabulary of the recognizer.\n\n        :rtype: list\n        :returns: A list of dictionaries. One dict for each alternative. Each\n                  dictionary typically contains two keys (though not\n                  all will be present in all cases)\n\n                  * ``transcript``: The detected text from the audio recording.\n                  * ``confidence``: The confidence in language detection, float\n                    between 0 and 1.\n        \"\"\"\n        api = self._client.speech_api\n        return api.recognize(self, language_code, max_alternatives,\n                             profanity_filter, speech_contexts)\n", "path": "speech/google/cloud/speech/sample.py"}]}