Exemplo n.º 1
0
        public void StartRecord()
        {
            try
            {
                _audioCapture = new WasapiLoopbackCapture();
                ffmpegProcess = new Process();
                ffmpegProcess.StartInfo.FileName               = "ffmpeg.exe";
                ffmpegProcess.StartInfo.Arguments              = $"-f f32le -ac 2 -ar 44100 -i - -ar 8000 -ac 1 -f s16le -";
                ffmpegProcess.StartInfo.RedirectStandardInput  = true;
                ffmpegProcess.StartInfo.RedirectStandardOutput = true;
                ffmpegProcess.StartInfo.UseShellExecute        = false;
                ffmpegProcess.StartInfo.CreateNoWindow         = true;
                ffmpegProcess.Start();


                _audioCapture.RecordingStopped += OnRecordingStopped;
                _audioCapture.DataAvailable    += OnDataAvailable;

                InfoMessage?.Invoke(this, "Запись...");

                _audioCapture.StartRecording();
            }
            catch (Exception e)
            {
                InfoMessage?.Invoke(this, $"Ошибка: {e.Message}");
            }
        }
Exemplo n.º 2
0
        public void Work()
        {
            try
            {
                filenames = new ConcurrentQueue <string>(Directory.GetFiles(_img_path, "*.jpg"));
            }
            catch (DirectoryNotFoundException exc)
            {
                ErrMessage?.Invoke("Directory doesn't exist!");
                return;
            }

            _stopSignal = new ManualResetEvent(false);
            var max_proc_count = Environment.ProcessorCount;

            Thread[] threads = new Thread[max_proc_count];
            for (int i = 0; i < max_proc_count; ++i)
            {
                InfoMessage?.Invoke("Statring thread");
                threads[i] = new Thread(worker);
                threads[i].Start();
            }

            InfoMessage?.Invoke("Done!");
        }
Exemplo n.º 3
0
        private void OnRecordingStopped(object sender, StoppedEventArgs err)
        {
            if (err.Exception != null)
            {
                InfoMessage?.Invoke(this, $"Ошибка: {err.Exception.Message}");
            }

            ffmpegProcess?.StandardOutput.Close();
            ffmpegProcess?.StandardInput.Close();
            ffmpegProcess?.Kill();

            _audioCapture.RecordingStopped -= OnRecordingStopped;
            _audioCapture.DataAvailable    -= OnDataAvailable;


            _audioCapture.Dispose();
            _audioCapture            = null;
            _threadSafeBoolBackValue = 0;

            Task.Run(() => { _transportService.SendFinalData(); }).Wait();
            Task.Run(() => { _transportService.CloseConnection(); }).Wait();
            InfoMessage?.Invoke(this, "Запись остановлена");
            RecordLevel?.Invoke(this, 0.0F);
            RecordStopped?.Invoke(this, EventArgs.Empty);
        }
Exemplo n.º 4
0
        public async Task TranscribeFile(string filePath)
        {
            InfoMessage.Invoke(this, "Обработка файла...");
            _cancellationTokenSource = new CancellationTokenSource();
            CancellationToken cancellationToken = _cancellationTokenSource.Token;

            var process = new Process();

            process.StartInfo.FileName               = "ffmpeg.exe";
            process.StartInfo.Arguments              = $"-i \"{filePath}\" -ar 8000 -ac 1 -f s16le -";
            process.StartInfo.RedirectStandardInput  = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.CreateNoWindow         = true;
            process.Start();


            var task = Task.Run(() =>
            {
                FFmpegPercentageParser ffmpegParser = new FFmpegPercentageParser();
                string line;
                int previousPercent;
                while ((line = process.StandardError.ReadLine()) != null && !cancellationToken.IsCancellationRequested)
                {
                    ffmpegParser.Parse(line);
                    if (ffmpegParser.GetPercentCompleted() is int currentPercent)
                    {
                        previousPercent = currentPercent;
                        PercentageTranscribed?.Invoke(this, currentPercent);
                    }
                }
            });

            var buffer = new byte[8000];
            int read;

            while ((read = process.StandardOutput.BaseStream.Read(buffer, 0, buffer.Length)) > 0 && !cancellationToken.IsCancellationRequested)
            {
                await _transportService.SendData(buffer, read);
            }
            await _transportService.SendFinalData();

            await _transportService.CloseConnection();

            process.Kill();
            _cancellationTokenSource.Dispose();
            _cancellationTokenSource = null;
            InfoMessage.Invoke(this, "Операция завершена");
        }
Exemplo n.º 5
0
        private void worker()
        {
            string name;

            while (filenames.TryDequeue(out name))
            {
                if (_stopSignal.WaitOne(0))
                {
                    ErrMessage?.Invoke("Stopping Thread by signal");
                    return;
                }
                ResultEvent?.Invoke(Predict(ImageToTensor(name), name));
            }
            InfoMessage?.Invoke("Stopping thread normally");
        }
Exemplo n.º 6
0
        //public void Stop() => _ct.Cancel();
        private void worker()
        {
            string name;

            while (filenames.TryDequeue(out name))
            {
                //Console.WriteLine("here working");
                if (_ct.IsCancellationRequested || _stopSignal.WaitOne(0))
                {
                    Console.WriteLine("sssss");
                    ErrMessage?.Invoke("Stopping Thread by signal");
                    return;
                }
                //Console.WriteLine("here after");
                var current_res = Predict_with_db(ImageToTensor(name), name);
                ResultEvent?.Invoke(current_res);
            }
            InfoMessage?.Invoke("Stopping thread normally");
        }
 private void ProcessServerResponse(object sender, string rawStr)
 {
     try
     {
         JObject respond = JObject.Parse(rawStr);
         if (respond.ContainsKey("partial"))
         {
             _transcriptionModel.Partial = respond["partial"].ToString();
         }
         if (respond.ContainsKey("text"))
         {
             _transcriptionModel.Text = respond["text"].ToString();
         }
         HandledServerResponse?.Invoke(this, _transcriptionModel.Text);
     }
     catch (JsonReaderException e)
     {
         InfoMessage?.Invoke(this, e.Message);
     }
 }
Exemplo n.º 8
0
 public void Stop()
 {
     _cancellationTokenSource?.Cancel();
     InfoMessage?.Invoke(this, "Обработка файла отменена");
 }
 protected virtual void OnInfoMessage(string e)
 {
     InfoMessage?.Invoke(this, e);
 }
Exemplo n.º 10
0
 public void StopRecording()
 {
     InfoMessage?.Invoke(this, "Запись останавливается...");
     _audioCapture?.StopRecording();
 }
Exemplo n.º 11
0
 protected void OnInfoMessage(string message)
 {
     InfoMessage?.Invoke(this, message);
 }
Exemplo n.º 12
0
 protected void InvokeInfoMessage(IReadOnlyCollection <InfoMessage> messages) => InfoMessage?.Invoke(messages);
Exemplo n.º 13
0
 internal void OnInfoMessage(MySqlInfoMessageEventArgs args)
 {
     InfoMessage?.Invoke(this, args);
 }
Exemplo n.º 14
0
 protected void LogInfoMessage(string message)
 {
     InfoMessage?.Invoke(message);
 }
Exemplo n.º 15
0
 internal void OnInfoMessage(string message) => InfoMessage?.Invoke(message);
Exemplo n.º 16
0
 private void LogSlideProcessing(string prefix, Slide slide)
 {
     InfoMessage?.Invoke(prefix + " " + slide.Info.Unit.Title + " - " + slide.Title);
 }
Exemplo n.º 17
0
 private void InfoMessageEvent(object sender, SqlInfoMessageEventArgs e)
 {
     InfoMessage?.Invoke(_connection, e);
 }
Exemplo n.º 18
0
 private void Conexion_InfoMessage(object sender, SqlInfoMessageEventArgs e)
 {
     InfoMessage?.Invoke(e);
 }
Exemplo n.º 19
0
 public static void Info(object sender, string message, string details = null)
 {
     InfoMessage?.Invoke(sender, message, details);
 }
Exemplo n.º 20
0
 private void TakoDbContext_InfoMessage(object sender, SqlInfoMessageEventArgs e)
 {
     InfoMessage?.Invoke(sender, e);
 }
Exemplo n.º 21
0
 private static void OnInfoMsg(string content)
 {
     InfoMessage?.Invoke(null, content);
 }
Exemplo n.º 22
0
 private void OnWarningMessage(IscException warning)
 {
     InfoMessage?.Invoke(this, new FbInfoMessageEventArgs(warning));
 }
Exemplo n.º 23
0
 internal void OnInfoMessage(string value)
 {
     InfoMessage?.Invoke(value);
 }