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 void AsyncRecognize() { // Snippet: AsyncRecognize(RecognitionConfig,RecognitionAudio,CallSettings) // Create client SpeechClient speechClient = SpeechClient.Create(); // Initialize request argument(s) RecognitionConfig config = new RecognitionConfig { Encoding = RecognitionConfig.Types.AudioEncoding.Flac, SampleRate = 44100, }; RecognitionAudio audio = new RecognitionAudio { Uri = "gs://bucket_name/file_name.flac", }; // Make the request Operation <AsyncRecognizeResponse> response = speechClient.AsyncRecognize(config, audio); // 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 }