/** * Режим потокового распозанвания текста */ static void DoSttStreaming(Options args, ILoggerFactory _loggerFactory) { RecognitionSpec rSpec = new RecognitionSpec() { LanguageCode = args.lang, ProfanityFilter = false, Model = args.model, PartialResults = false, //возвращать только финальные результаты false AudioEncoding = args.audioEncoding, SampleRateHertz = args.sampleRate }; SpeechKitSttStreamClient speechKitClient = new SpeechKitSttStreamClient(new Uri("https://stt.api.cloud.yandex.net:443"), args.folderId, args.iamToken, rSpec, _loggerFactory); // // Subscribe for speech to text events comming from SpeechKit SpeechKitClient.SpeechToTextResponseReader.ChunkRecived += SpeechToTextResponseReader_ChunksRecived; FileStreamReader filereader = new FileStreamReader(args.inputFilePath); // Subscribe SpeechKitClient for next portion of audio data filereader.AudioBinaryRecived += speechKitClient.Listener_SpeechKitSend; filereader.ReadAudioFile().Wait(); Log.Information("Shutting down SpeechKitStreamClient gRPC connections."); speechKitClient.Dispose(); if (!string.IsNullOrEmpty(notFinalBuf)) { outFile.Write(Encoding.UTF8.GetBytes(notFinalBuf)); //Write final results into file } }
/** * Режим потокового распозанвания текста */ static void DoSttStreaming(ILoggerFactory _loggerFactory) { SpeechKitSttStreamClient speechKitClient = new SpeechKitSttStreamClient(new Uri(args.serviceUri), args, _loggerFactory); //https://stt.api.cloud.yandex.net:443 SpeechToTextResponseReader.ChunkRecived += SpeechToTextResponseReader_ChunksRecived; CancellationToken cancelToken = cancelSource.Token; speechKitClient.SendAsrData(File.ReadAllBytes(args.inputFilePath), cancelToken); while (true) { Thread.Sleep(200); if (cancelToken.IsCancellationRequested) { Log.Information("Shutting down SpeechKitStreamClient gRPC connections."); speechKitClient.Dispose(); return; } } Log.Information($"Final results output file: {FinalTextResultsOutFile}"); Log.Information($"Partial results output file: {PartialTextResultsOutFile}"); Log.Information($"Trace service output file: {TraceResultsOutFile}"); }