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}"); } }
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!"); }
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); }
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, "Операция завершена"); }
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"); }
//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); } }
public void Stop() { _cancellationTokenSource?.Cancel(); InfoMessage?.Invoke(this, "Обработка файла отменена"); }
protected virtual void OnInfoMessage(string e) { InfoMessage?.Invoke(this, e); }
public void StopRecording() { InfoMessage?.Invoke(this, "Запись останавливается..."); _audioCapture?.StopRecording(); }
protected void OnInfoMessage(string message) { InfoMessage?.Invoke(this, message); }
protected void InvokeInfoMessage(IReadOnlyCollection <InfoMessage> messages) => InfoMessage?.Invoke(messages);
internal void OnInfoMessage(MySqlInfoMessageEventArgs args) { InfoMessage?.Invoke(this, args); }
protected void LogInfoMessage(string message) { InfoMessage?.Invoke(message); }
internal void OnInfoMessage(string message) => InfoMessage?.Invoke(message);
private void LogSlideProcessing(string prefix, Slide slide) { InfoMessage?.Invoke(prefix + " " + slide.Info.Unit.Title + " - " + slide.Title); }
private void InfoMessageEvent(object sender, SqlInfoMessageEventArgs e) { InfoMessage?.Invoke(_connection, e); }
private void Conexion_InfoMessage(object sender, SqlInfoMessageEventArgs e) { InfoMessage?.Invoke(e); }
public static void Info(object sender, string message, string details = null) { InfoMessage?.Invoke(sender, message, details); }
private void TakoDbContext_InfoMessage(object sender, SqlInfoMessageEventArgs e) { InfoMessage?.Invoke(sender, e); }
private static void OnInfoMsg(string content) { InfoMessage?.Invoke(null, content); }
private void OnWarningMessage(IscException warning) { InfoMessage?.Invoke(this, new FbInfoMessageEventArgs(warning)); }
internal void OnInfoMessage(string value) { InfoMessage?.Invoke(value); }