public void AsyncRecognize_RequestObject() { // Snippet: AsyncRecognize(AsyncRecognizeRequest,CallSettings) // Create client SpeechClient speechClient = SpeechClient.Create(); // Initialize request argument(s) AsyncRecognizeRequest request = new AsyncRecognizeRequest { Config = new RecognitionConfig(), Audio = new RecognitionAudio(), }; // Make the request Operation <AsyncRecognizeResponse> response = speechClient.AsyncRecognize(request); // Poll until the returned long-running operation is complete Operation <AsyncRecognizeResponse> completedResponse = response.PollUntilCompleted(); // Retrieve the operation result AsyncRecognizeResponse result = completedResponse.Result; // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation <AsyncRecognizeResponse> retrievedResponse = speechClient.PollOnceAsyncRecognize(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result AsyncRecognizeResponse retrievedResult = retrievedResponse.Result; } // End snippet }
public async Task AsyncRecognizeAsync() { // Snippet: AsyncRecognizeAsync(RecognitionConfig,RecognitionAudio,CallSettings) // Additional: AsyncRecognizeAsync(RecognitionConfig,RecognitionAudio,CancellationToken) // Create client SpeechClient speechClient = await SpeechClient.CreateAsync(); // Initialize request argument(s) RecognitionConfig config = new RecognitionConfig(); RecognitionAudio audio = new RecognitionAudio(); // Make the request Operation <AsyncRecognizeResponse> response = await speechClient.AsyncRecognizeAsync(config, audio); // Poll until the returned long-running operation is complete Operation <AsyncRecognizeResponse> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result AsyncRecognizeResponse result = completedResponse.Result; // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation <AsyncRecognizeResponse> retrievedResponse = await speechClient.PollOnceAsyncRecognizeAsync(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result AsyncRecognizeResponse retrievedResult = retrievedResponse.Result; } // End snippet }
public async Task AsyncRecognizeAsync_RequestObject() { // Snippet: AsyncRecognizeAsync(AsyncRecognizeRequest,CallSettings) // Create client SpeechClient speechClient = await SpeechClient.CreateAsync(); // Initialize request argument(s) AsyncRecognizeRequest request = new AsyncRecognizeRequest { Config = new RecognitionConfig { Encoding = RecognitionConfig.Types.AudioEncoding.Flac, SampleRate = 44100, }, Audio = new RecognitionAudio { Uri = "gs://bucket_name/file_name.flac", }, }; // Make the request Operation <AsyncRecognizeResponse> response = await speechClient.AsyncRecognizeAsync(request); // Poll until the returned long-running operation is complete Operation <AsyncRecognizeResponse> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result AsyncRecognizeResponse result = completedResponse.Result; // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation <AsyncRecognizeResponse> retrievedResponse = await speechClient.PollOnceAsyncRecognizeAsync(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result AsyncRecognizeResponse retrievedResult = retrievedResponse.Result; } // End snippet }