Ejemplo n.º 1
0
        public LongRunningRecognizeResponse TranscribeInCloud(TranscribeParameters transParams)
        {
            // var speechClient = SpeechClient.Create();

            string           fileOnCloudStorage = "gs://" + transParams.GoogleCloudBucketName + "/" + transParams.objectName;
            RecognitionAudio recogAudio         = RecognitionAudio.FromStorageUri(fileOnCloudStorage);

            SpeakerDiarizationConfig sdc = new SpeakerDiarizationConfig()
            {
                EnableSpeakerDiarization = true,
                MinSpeakerCount          = transParams.MinSpeakerCount,
                MaxSpeakerCount          = transParams.MaxSpeakerCount
            };

            var longOperation = speechClient.LongRunningRecognize(new RecognitionConfig()
            {
                Encoding                   = RecognitionConfig.Types.AudioEncoding.Flac,
                SampleRateHertz            = 44100,
                EnableWordTimeOffsets      = true,
                LanguageCode               = transParams.language,
                EnableAutomaticPunctuation = true,
                DiarizationConfig          = sdc,
                SpeechContexts             =
                {
                    new SpeechContext {
                        Phrases =     { transParams.phrases}
                    }
                }
            }, recogAudio);

            longOperation = longOperation.PollUntilCompleted();
            var response = longOperation.Result;

            return(response);
        }
Ejemplo n.º 2
0
        public LongRunningRecognizeResponse UploadAndTranscribeInCloud(TranscribeParameters transParams)
        {
            UploadToCloudIfNeeded(transParams);

            LongRunningRecognizeResponse response = TranscribeInCloud(transParams);

            return(response);
        }
Ejemplo n.º 3
0
        private void UploadToCloudIfNeeded(TranscribeParameters transParams)
        {
            GoogleBucket gb = new GoogleBucket();

            if (transParams.useAudioFileAlreadyInCloud)
            {
                // Only upload if not in cloud
                if (!gb.IsObjectInBucket(transParams.GoogleCloudBucketName, transParams.objectName))
                {
                    gb.UploadFile(transParams.GoogleCloudBucketName, transParams.audiofilePath, transParams.objectName, "audio /x-flac");
                }
            }
        }
Ejemplo n.º 4
0
        public Transcribed_Dto TranscribeAudioFile(TranscribeParameters transParams, string rawResponseFile = null)
        {
            LongRunningRecognizeResponse response = UploadAndTranscribeInCloud(transParams);

            // Save the raw response, if we were passed a file path.
            if (rawResponseFile != "")
            {
                string responseString = JsonConvert.SerializeObject(response, Formatting.Indented);
                File.WriteAllText(rawResponseFile, responseString);
            }

            Transcribed_Dto resp = TransformResponse.Simpify(response.Results);

            return(TransformResponse.FixSpeakerTags(resp));
        }