Skip to content

Commit

Permalink
feat: StreamingSynthesize now supports opus
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 707168599

Source-Link: googleapis/googleapis@d985436

Source-Link: googleapis/googleapis-gen@3fcc3af
Copy-Tag: eyJwIjoiYXBpcy9Hb29nbGUuQ2xvdWQuVGV4dFRvU3BlZWNoLlYxQmV0YTEvLk93bEJvdC55YW1sIiwiaCI6IjNmY2MzYWZiZjhjOTIwODRjYzRhMzAyMzJhNzZjYTI0NzQ4OWMzZDAifQ==
  • Loading branch information
gcf-owl-bot[bot] committed Dec 17, 2024
1 parent 8c0fdf1 commit f3023c2
Show file tree
Hide file tree
Showing 27 changed files with 10,427 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net462</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../Google.Cloud.TextToSpeech.V1Beta1/Google.Cloud.TextToSpeech.V1Beta1.csproj" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Generated code. DO NOT EDIT!

namespace GoogleCSharpSnippets
{
// [START texttospeech_v1beta1_generated_TextToSpeech_ListVoices_async_flattened]
using Google.Cloud.TextToSpeech.V1Beta1;
using System.Threading.Tasks;

public sealed partial class GeneratedTextToSpeechClientSnippets
{
/// <summary>Snippet for ListVoicesAsync</summary>
/// <remarks>
/// 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://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
/// </remarks>
public async Task ListVoicesAsync()
{
// Create client
TextToSpeechClient textToSpeechClient = await TextToSpeechClient.CreateAsync();
// Initialize request argument(s)
string languageCode = "";
// Make the request
ListVoicesResponse response = await textToSpeechClient.ListVoicesAsync(languageCode);
}
}
// [END texttospeech_v1beta1_generated_TextToSpeech_ListVoices_async_flattened]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Generated code. DO NOT EDIT!

namespace GoogleCSharpSnippets
{
// [START texttospeech_v1beta1_generated_TextToSpeech_ListVoices_async]
using Google.Cloud.TextToSpeech.V1Beta1;
using System.Threading.Tasks;

public sealed partial class GeneratedTextToSpeechClientSnippets
{
/// <summary>Snippet for ListVoicesAsync</summary>
/// <remarks>
/// 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://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
/// </remarks>
public async Task ListVoicesRequestObjectAsync()
{
// Create client
TextToSpeechClient textToSpeechClient = await TextToSpeechClient.CreateAsync();
// Initialize request argument(s)
ListVoicesRequest request = new ListVoicesRequest { LanguageCode = "", };
// Make the request
ListVoicesResponse response = await textToSpeechClient.ListVoicesAsync(request);
}
}
// [END texttospeech_v1beta1_generated_TextToSpeech_ListVoices_async]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Generated code. DO NOT EDIT!

namespace GoogleCSharpSnippets
{
// [START texttospeech_v1beta1_generated_TextToSpeech_ListVoices_sync]
using Google.Cloud.TextToSpeech.V1Beta1;

public sealed partial class GeneratedTextToSpeechClientSnippets
{
/// <summary>Snippet for ListVoices</summary>
/// <remarks>
/// 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://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
/// </remarks>
public void ListVoicesRequestObject()
{
// Create client
TextToSpeechClient textToSpeechClient = TextToSpeechClient.Create();
// Initialize request argument(s)
ListVoicesRequest request = new ListVoicesRequest { LanguageCode = "", };
// Make the request
ListVoicesResponse response = textToSpeechClient.ListVoices(request);
}
}
// [END texttospeech_v1beta1_generated_TextToSpeech_ListVoices_sync]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Generated code. DO NOT EDIT!

namespace GoogleCSharpSnippets
{
// [START texttospeech_v1beta1_generated_TextToSpeech_ListVoices_sync_flattened]
using Google.Cloud.TextToSpeech.V1Beta1;

public sealed partial class GeneratedTextToSpeechClientSnippets
{
/// <summary>Snippet for ListVoices</summary>
/// <remarks>
/// 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://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
/// </remarks>
public void ListVoices()
{
// Create client
TextToSpeechClient textToSpeechClient = TextToSpeechClient.Create();
// Initialize request argument(s)
string languageCode = "";
// Make the request
ListVoicesResponse response = textToSpeechClient.ListVoices(languageCode);
}
}
// [END texttospeech_v1beta1_generated_TextToSpeech_ListVoices_sync_flattened]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Generated code. DO NOT EDIT!

namespace GoogleCSharpSnippets
{
// [START texttospeech_v1beta1_generated_TextToSpeech_StreamingSynthesize_sync]
using Google.Api.Gax.Grpc;
using Google.Cloud.TextToSpeech.V1Beta1;
using System.Threading.Tasks;

public sealed partial class GeneratedTextToSpeechClientSnippets
{
/// <summary>Snippet for StreamingSynthesize</summary>
/// <remarks>
/// 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://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
/// </remarks>
public async Task StreamingSynthesize()
{
// Create client
TextToSpeechClient textToSpeechClient = TextToSpeechClient.Create();
// Initialize streaming call, retrieving the stream object
using TextToSpeechClient.StreamingSynthesizeStream response = textToSpeechClient.StreamingSynthesize();

// Sending requests and retrieving responses can be arbitrarily interleaved
// Exact sequence will depend on client/server behavior

// Create task to do something with responses from server
Task responseHandlerTask = Task.Run(async () =>
{
// Note that C# 8 code can use await foreach
AsyncResponseStream<StreamingSynthesizeResponse> responseStream = response.GetResponseStream();
while (await responseStream.MoveNextAsync())
{
StreamingSynthesizeResponse responseItem = responseStream.Current;
// Do something with streamed response
}
// The response stream has completed
});

// Send requests to the server
bool done = false;
while (!done)
{
// Initialize a request
StreamingSynthesizeRequest request = new StreamingSynthesizeRequest
{
StreamingConfig = new StreamingSynthesizeConfig(),
};
// Stream a request to the server
await response.WriteAsync(request);
// Set "done" to true when sending requests is complete
}

// Complete writing requests to the stream
await response.WriteCompleteAsync();
// Await the response handler
// This will complete once all server responses have been processed
await responseHandlerTask;
}
}
// [END texttospeech_v1beta1_generated_TextToSpeech_StreamingSynthesize_sync]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Generated code. DO NOT EDIT!

namespace GoogleCSharpSnippets
{
// [START texttospeech_v1beta1_generated_TextToSpeech_SynthesizeSpeech_async_flattened]
using Google.Cloud.TextToSpeech.V1Beta1;
using System.Threading.Tasks;

public sealed partial class GeneratedTextToSpeechClientSnippets
{
/// <summary>Snippet for SynthesizeSpeechAsync</summary>
/// <remarks>
/// 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://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
/// </remarks>
public async Task SynthesizeSpeechAsync()
{
// Create client
TextToSpeechClient textToSpeechClient = await TextToSpeechClient.CreateAsync();
// Initialize request argument(s)
SynthesisInput input = new SynthesisInput();
VoiceSelectionParams voice = new VoiceSelectionParams();
AudioConfig audioConfig = new AudioConfig();
// Make the request
SynthesizeSpeechResponse response = await textToSpeechClient.SynthesizeSpeechAsync(input, voice, audioConfig);
}
}
// [END texttospeech_v1beta1_generated_TextToSpeech_SynthesizeSpeech_async_flattened]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Generated code. DO NOT EDIT!

namespace GoogleCSharpSnippets
{
// [START texttospeech_v1beta1_generated_TextToSpeech_SynthesizeSpeech_async]
using Google.Cloud.TextToSpeech.V1Beta1;
using System.Threading.Tasks;

public sealed partial class GeneratedTextToSpeechClientSnippets
{
/// <summary>Snippet for SynthesizeSpeechAsync</summary>
/// <remarks>
/// 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://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
/// </remarks>
public async Task SynthesizeSpeechRequestObjectAsync()
{
// Create client
TextToSpeechClient textToSpeechClient = await TextToSpeechClient.CreateAsync();
// Initialize request argument(s)
SynthesizeSpeechRequest request = new SynthesizeSpeechRequest
{
Input = new SynthesisInput(),
Voice = new VoiceSelectionParams(),
AudioConfig = new AudioConfig(),
EnableTimePointing =
{
SynthesizeSpeechRequest.Types.TimepointType.Unspecified,
},
AdvancedVoiceOptions = new AdvancedVoiceOptions(),
};
// Make the request
SynthesizeSpeechResponse response = await textToSpeechClient.SynthesizeSpeechAsync(request);
}
}
// [END texttospeech_v1beta1_generated_TextToSpeech_SynthesizeSpeech_async]
}
Loading

0 comments on commit f3023c2

Please sign in to comment.