Skip to content

Commit

Permalink
feat: [google-cloud-texttospeech] A new method StreamingSynthesize
Browse files Browse the repository at this point in the history
…is added to service `TextToSpeech` (#13012)

- [ ] Regenerate this pull request now.

BEGIN_COMMIT_OVERRIDE
feat: A new method `StreamingSynthesize` is added to service
`TextToSpeech`
docs: A comment for field `name` in message
`.google.cloud.texttospeech.v1beta1.VoiceSelectionParams` is changed
docs: A comment for field `name` in message
`.google.cloud.texttospeech.v1.VoiceSelectionParams` is changed
END_COMMIT_OVERRIDE



PiperOrigin-RevId: 662978887

Source-Link:
googleapis/googleapis@195c051

Source-Link:
googleapis/googleapis-gen@1a53efd
Copy-Tag:
eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXRleHR0b3NwZWVjaC8uT3dsQm90LnlhbWwiLCJoIjoiMWE1M2VmZDQwMzRmMTJiZDQ1M2MzNmYxZjNiOWRiYWYwMTY5NWNmNSJ9

feat: A new method `StreamingSynthesize` is added to service
`TextToSpeech`

docs: A comment for field `name` in message
`.google.cloud.texttospeech.v1.VoiceSelectionParams` is changed
PiperOrigin-RevId: 662708702

Source-Link:
googleapis/googleapis@569fc73

Source-Link:
googleapis/googleapis-gen@f34f8a1
Copy-Tag:
eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXRleHR0b3NwZWVjaC8uT3dsQm90LnlhbWwiLCJoIjoiZjM0ZjhhMWQ5MDY0NmQzMTk3YTNkMDMwOGQ4ZTE0NWM3MGY3N2Y0MSJ9

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
gcf-owl-bot[bot] and gcf-owl-bot[bot] authored Aug 19, 2024
1 parent fdebbf2 commit 973e48a
Showing 40 changed files with 1,881 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -37,6 +37,10 @@
ListVoicesRequest,
ListVoicesResponse,
SsmlVoiceGender,
StreamingSynthesisInput,
StreamingSynthesizeConfig,
StreamingSynthesizeRequest,
StreamingSynthesizeResponse,
SynthesisInput,
SynthesizeSpeechRequest,
SynthesizeSpeechResponse,
@@ -58,6 +62,10 @@
"CustomVoiceParams",
"ListVoicesRequest",
"ListVoicesResponse",
"StreamingSynthesisInput",
"StreamingSynthesizeConfig",
"StreamingSynthesizeRequest",
"StreamingSynthesizeResponse",
"SynthesisInput",
"SynthesizeSpeechRequest",
"SynthesizeSpeechResponse",
Original file line number Diff line number Diff line change
@@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
__version__ = "2.16.5" # {x-release-please-version}
__version__ = "0.0.0" # {x-release-please-version}
Original file line number Diff line number Diff line change
@@ -30,6 +30,10 @@
ListVoicesRequest,
ListVoicesResponse,
SsmlVoiceGender,
StreamingSynthesisInput,
StreamingSynthesizeConfig,
StreamingSynthesizeRequest,
StreamingSynthesizeResponse,
SynthesisInput,
SynthesizeSpeechRequest,
SynthesizeSpeechResponse,
@@ -51,6 +55,10 @@
"ListVoicesRequest",
"ListVoicesResponse",
"SsmlVoiceGender",
"StreamingSynthesisInput",
"StreamingSynthesizeConfig",
"StreamingSynthesizeRequest",
"StreamingSynthesizeResponse",
"SynthesisInput",
"SynthesizeLongAudioMetadata",
"SynthesizeLongAudioRequest",
Original file line number Diff line number Diff line change
@@ -15,6 +15,11 @@
"list_voices"
]
},
"StreamingSynthesize": {
"methods": [
"streaming_synthesize"
]
},
"SynthesizeSpeech": {
"methods": [
"synthesize_speech"
@@ -30,6 +35,11 @@
"list_voices"
]
},
"StreamingSynthesize": {
"methods": [
"streaming_synthesize"
]
},
"SynthesizeSpeech": {
"methods": [
"synthesize_speech"
@@ -45,6 +55,11 @@
"list_voices"
]
},
"StreamingSynthesize": {
"methods": [
"streaming_synthesize"
]
},
"SynthesizeSpeech": {
"methods": [
"synthesize_speech"
Original file line number Diff line number Diff line change
@@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
__version__ = "2.16.5" # {x-release-please-version}
__version__ = "0.0.0" # {x-release-please-version}
Original file line number Diff line number Diff line change
@@ -14,9 +14,11 @@
# limitations under the License.
#
from collections import OrderedDict
import functools
import re
from typing import (
AsyncIterable,
AsyncIterator,
Awaitable,
Callable,
Dict,
Mapping,
@@ -184,9 +186,7 @@ def universe_domain(self) -> str:
"""
return self._client._universe_domain

get_transport_class = functools.partial(
type(TextToSpeechClient).get_transport_class, type(TextToSpeechClient)
)
get_transport_class = TextToSpeechClient.get_transport_class

def __init__(
self,
@@ -495,6 +495,100 @@ async def sample_synthesize_speech():
# Done; return the response.
return response

def streaming_synthesize(
self,
requests: Optional[AsyncIterator[cloud_tts.StreamingSynthesizeRequest]] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> Awaitable[AsyncIterable[cloud_tts.StreamingSynthesizeResponse]]:
r"""Performs bidirectional streaming speech synthesis:
receive audio while sending text.
.. code-block:: python
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import texttospeech_v1
async def sample_streaming_synthesize():
# Create a client
client = texttospeech_v1.TextToSpeechAsyncClient()
# Initialize request argument(s)
streaming_config = texttospeech_v1.StreamingSynthesizeConfig()
streaming_config.voice.language_code = "language_code_value"
request = texttospeech_v1.StreamingSynthesizeRequest(
streaming_config=streaming_config,
)
# This method expects an iterator which contains
# 'texttospeech_v1.StreamingSynthesizeRequest' objects
# Here we create a generator that yields a single `request` for
# demonstrative purposes.
requests = [request]
def request_generator():
for request in requests:
yield request
# Make the request
stream = await client.streaming_synthesize(requests=request_generator())
# Handle the response
async for response in stream:
print(response)
Args:
requests (AsyncIterator[`google.cloud.texttospeech_v1.types.StreamingSynthesizeRequest`]):
The request object AsyncIterator. Request message for the ``StreamingSynthesize`` method.
Multiple ``StreamingSynthesizeRequest`` messages are
sent in one call. The first message must contain a
``streaming_config`` that fully specifies the request
configuration and must not contain ``input``. All
subsequent messages must only have ``input`` set.
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
Returns:
AsyncIterable[google.cloud.texttospeech_v1.types.StreamingSynthesizeResponse]:
StreamingSynthesizeResponse is the only message returned to the
client by StreamingSynthesize method. A series of
zero or more StreamingSynthesizeResponse messages are
streamed back to the client.
"""

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._client._transport._wrapped_methods[
self._client._transport.streaming_synthesize
]

# Validate the universe domain.
self._client._validate_universe_domain()

# Send the request.
response = rpc(
requests,
retry=retry,
timeout=timeout,
metadata=metadata,
)

# Done; return the response.
return response

async def list_operations(
self,
request: Optional[operations_pb2.ListOperationsRequest] = None,
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@
from typing import (
Callable,
Dict,
Iterable,
Iterator,
Mapping,
MutableMapping,
MutableSequence,
@@ -659,7 +661,7 @@ def __init__(
transport_init: Union[
Type[TextToSpeechTransport], Callable[..., TextToSpeechTransport]
] = (
type(self).get_transport_class(transport)
TextToSpeechClient.get_transport_class(transport)
if isinstance(transport, str) or transport is None
else cast(Callable[..., TextToSpeechTransport], transport)
)
@@ -908,6 +910,98 @@ def sample_synthesize_speech():
# Done; return the response.
return response

def streaming_synthesize(
self,
requests: Optional[Iterator[cloud_tts.StreamingSynthesizeRequest]] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> Iterable[cloud_tts.StreamingSynthesizeResponse]:
r"""Performs bidirectional streaming speech synthesis:
receive audio while sending text.
.. code-block:: python
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import texttospeech_v1
def sample_streaming_synthesize():
# Create a client
client = texttospeech_v1.TextToSpeechClient()
# Initialize request argument(s)
streaming_config = texttospeech_v1.StreamingSynthesizeConfig()
streaming_config.voice.language_code = "language_code_value"
request = texttospeech_v1.StreamingSynthesizeRequest(
streaming_config=streaming_config,
)
# This method expects an iterator which contains
# 'texttospeech_v1.StreamingSynthesizeRequest' objects
# Here we create a generator that yields a single `request` for
# demonstrative purposes.
requests = [request]
def request_generator():
for request in requests:
yield request
# Make the request
stream = client.streaming_synthesize(requests=request_generator())
# Handle the response
for response in stream:
print(response)
Args:
requests (Iterator[google.cloud.texttospeech_v1.types.StreamingSynthesizeRequest]):
The request object iterator. Request message for the ``StreamingSynthesize`` method.
Multiple ``StreamingSynthesizeRequest`` messages are
sent in one call. The first message must contain a
``streaming_config`` that fully specifies the request
configuration and must not contain ``input``. All
subsequent messages must only have ``input`` set.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
Returns:
Iterable[google.cloud.texttospeech_v1.types.StreamingSynthesizeResponse]:
StreamingSynthesizeResponse is the only message returned to the
client by StreamingSynthesize method. A series of
zero or more StreamingSynthesizeResponse messages are
streamed back to the client.
"""

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._transport._wrapped_methods[self._transport.streaming_synthesize]

# Validate the universe domain.
self._validate_universe_domain()

# Send the request.
response = rpc(
requests,
retry=retry,
timeout=timeout,
metadata=metadata,
)

# Done; return the response.
return response

def __enter__(self) -> "TextToSpeechClient":
return self

Original file line number Diff line number Diff line change
@@ -139,6 +139,11 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=None,
client_info=client_info,
),
self.streaming_synthesize: gapic_v1.method.wrap_method(
self.streaming_synthesize,
default_timeout=None,
client_info=client_info,
),
}

def close(self):
@@ -171,6 +176,18 @@ def synthesize_speech(
]:
raise NotImplementedError()

@property
def streaming_synthesize(
self,
) -> Callable[
[cloud_tts.StreamingSynthesizeRequest],
Union[
cloud_tts.StreamingSynthesizeResponse,
Awaitable[cloud_tts.StreamingSynthesizeResponse],
],
]:
raise NotImplementedError()

@property
def list_operations(
self,
Loading

0 comments on commit 973e48a

Please sign in to comment.