Exemplo n.º 1
0
        public object AnalyzeSoundToText(List <RecognitionAudio> target)
        {
            foreach (var sound in target)
            {
                try
                {
                    var response       = client.LongRunningRecognize(this.recognitionConfig, sound);
                    var responseResult = response.PollUntilCompleted();

                    var i             = 0;
                    var soundFilename = JObject.Parse(sound.ToString())["uri"].ToString().Replace("gs:", "").Replace("/", "_");

                    foreach (var result in responseResult.Result.Results)
                    {
                        var timestamp = SpeechConnector.UnixTimeNow();
                        using (StreamWriter rdr = new StreamWriter($"result_{soundFilename}_{timestamp}_{i}.txt"))
                        {
                            foreach (var alternative in result.Alternatives)
                            {
                                rdr.WriteLine(alternative.Transcript);
                            }
                            rdr.Close();
                            Console.WriteLine($"The result saved the file -> result_{soundFilename}_{timestamp}_{i}_.txt");
                        }
                        i++;
                    }
                }
                catch (Grpc.Core.RpcException e)
                {
                    Console.WriteLine(e);
                    Console.WriteLine("Something wrong :( Skipping this file");
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            //var projectId = "peppy-nation-221511"; // 바꿔야 할 부분
            //var bucket = "voice-device"; // 바꿔야 할 부분

            Console.Write("Input your project id: ");
            var projectId = Console.ReadLine();

            Console.Write("Input your bucket: ");
            var bucket = Console.ReadLine();


            var connector       = new CloudPlatformConnector(projectId);
            var speechConnector = new SpeechConnector(connector).Connect();

            bool isStorageConnected = connector.IsConnectedStorageClient(bucket);

            if (!isStorageConnected)
            {
                throw new TypeAccessException($"Can't connected {projectId}@{bucket}");
            }

            var waveExtensionFiles = connector.GetSpecificFileExtension("flac"); // wav, flac

            var index = 0;

            Console.WriteLine("\n===== FILE LIST =====\n");
            foreach (var filename in waveExtensionFiles)
            {
                Console.WriteLine($"[{index}] filename: {filename}");
                index++;
            }
            Console.WriteLine("\n====================");

            var recognitionAudioFiles = speechConnector.ConvertRecognitionAudioFiles(waveExtensionFiles);

            Console.WriteLine("Analyzing file on Google Cloud platform ...");
            speechConnector.AnalyzeSoundToText(recognitionAudioFiles);

            Console.WriteLine("Finished. Press any key to exit the program ...");
            Console.ReadLine();
        }