public static void HandleStreamingRecognitionCommand(
            uint sampleRate,
            string audioEncoding,
            uint channelsCount,
            uint maxAlternatives,
            bool disableAutomaticPunctation,
            bool doNotPerformVad,
            float silenceDurationThreshold,
            string audioPath,
            bool enableInterimResults,
            bool singleUtterance
            )
        {
            var streamingRecognitionConfig = CreateStreamingRecognitionConfig(
                sampleRate,
                audioEncoding,
                channelsCount,
                maxAlternatives,
                disableAutomaticPunctation,
                enableInterimResults,
                singleUtterance
                );


            ConfigurateVAD(
                streamingRecognitionConfig.Config,
                silenceDurationThreshold,
                doNotPerformVad
                );

            using (var stream = GetAudioStream(audioPath, audioEncoding))
            {
                _client.StreamingRecognize(streamingRecognitionConfig, stream).Wait();
            }
        }
Ejemplo n.º 2
0
        static void gRPc_connect(string path)
        {
            // создаем канал для обмена сообщениями с сервером
            // параметр - адрес сервера gRPC



            // создаем клиента

            //  var client = new Greeter.GreeterClient(channel);
            // var mp3 = new MP3File(@"C:\Users\IlinKS\source\repos\JWT_gRPC_console\JWT_gRPC_console\2020.10.12_21.15.41_79214430425_incoming_mixed_79098420960.mp3","testik");
            // string path = @"C:\Users\IlinKS\source\repos\JWT_gRPC_console\JWT_gRPC_console\2020.10.12_21.15.41_79214430425_incoming_mixed_79098420960.mp3";
            // string path = @"c:\Users\ilinks\source\repos\JWT_gRPC_console\JWT_gRPC_console\6650322009_89136872782_2020-01-24_08_24_12.wav";

            var audio = TagLib.File.Create(path);

            var vkc = new VoiceKitClient("bnZ6cWRvcWJncWNud2dqcGxtZ21ndXVvZXdjaWpueHk=m.rogencovfilbert", "YXlzdXBvaWhrdmZzZmtvYXZtb3plaHZqeGlrcGZ1d2c=");

            // первый запрос
            StreamingRecognitionConfig streaming_config = new StreamingRecognitionConfig();

            streaming_config.Config = new RecognitionConfig();

            streaming_config.Config.SampleRateHertz = (uint)audio.Properties.AudioSampleRate;
            streaming_config.Config.NumChannels     = (uint)audio.Properties.AudioChannels;

            audio.Dispose();

//           using FileStream fstream =  File.Open(path, FileMode.Open);

            switch (Path.GetExtension(path))
            {
            case ".mp3":
                streaming_config.Config.Encoding = AudioEncoding.MpegAudio;
                vkc.StreamingRecognize(streaming_config, File.Open(path, FileMode.Open)).GetAwaiter().GetResult();
                break;

            case ".wav":
                streaming_config.Config.Encoding = AudioEncoding.Linear16;
                vkc.StreamingRecognizeWAV(streaming_config, WavToPcmConvert(path)).GetAwaiter().GetResult();
                break;
            }



            return;
        }