Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion speech/google/cloud/speech/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from base64 import b64encode

from google.cloud._helpers import _to_bytes
from google.cloud._helpers import _bytes_to_unicode
from google.cloud import client as client_module
from google.cloud.speech.connection import Connection
from google.cloud.speech.encoding import Encoding
Expand Down Expand Up @@ -237,7 +238,8 @@ def _build_request_data(sample, language_code=None, max_alternatives=None,
:returns: Dictionary with required data for Google Speech API.
"""
if sample.content is not None:
audio = {'content': b64encode(_to_bytes(sample.content))}
audio = {'content':
_bytes_to_unicode(b64encode(_to_bytes(sample.content)))}
else:
audio = {'uri': sample.source_uri}

Expand Down
8 changes: 5 additions & 3 deletions speech/unit_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ def test_create_sample_from_client(self):
self.assertEqual(content_sample.encoding, Encoding.FLAC)

def test_sync_recognize_content_with_optional_parameters(self):
import base64
from base64 import b64encode
from google.cloud._helpers import _to_bytes
from google.cloud._helpers import _bytes_to_unicode

from google.cloud.speech.encoding import Encoding
from google.cloud.speech.sample import Sample
from unit_tests._fixtures import SYNC_RECOGNIZE_RESPONSE

_B64_AUDIO_CONTENT = base64.b64encode(_to_bytes(self.AUDIO_CONTENT))
_AUDIO_CONTENT = _to_bytes(self.AUDIO_CONTENT)
_B64_AUDIO_CONTENT = _bytes_to_unicode(b64encode(_AUDIO_CONTENT))
RETURNED = SYNC_RECOGNIZE_RESPONSE
REQUEST = {
'config': {
Expand Down