public async Task RecorderTest()
        {
            using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(15));

            await BaseTests.BaseInstanceTestAsync <IRecorder>(
                GetFullName(typeof(NAudioRecorder)),
                async (instance, cancellationToken) =>
            {
                instance.RawDataReceived += (_, args) =>
                {
                    Console.WriteLine(
                        $"{nameof(instance.RawDataReceived)}: {args.RawData?.Count ?? 0}, {args.WavData?.Count ?? 0}");
                };
                await instance.InitializeAsync(cancellationToken);

                if (!NAudioRecorder.GetAvailableDevices().Any())
                {
                    return;
                }

                await instance.StartAsync(cancellationToken);

                await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);

                await instance.StopAsync(cancellationToken);
            },
                cancellationTokenSource.Token);
        }
예제 #2
0
파일: Form1.cs 프로젝트: amanowar/storybook
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var videoProvider   = new OcvVideoProvider(new ObservableTimer(this.timer));
            var videoRecorder   = new VideoRecorder();
            var audioRecorder   = new NAudioRecorder();
            var audioPlayer     = new NAudioPlayer();
            var audioRepository = new NAudioRepository();
            var brain           = new OcvBrain();

            controller = new Controller();

            videoProvider.Init();
            videoRecorder.Init(videoProvider);
            audioRecorder.Init();
            brain.Init();
            controller.Init(brain, videoProvider, videoRecorder, audioRecorder, audioPlayer, audioRepository);

            lifetimeSubscriptions = new CompositeDisposable()
            {
                brain.FrameRecognized.ObserveOn(this).Subscribe(OnFrameRecognized),
                videoProvider.FrameAvailable.ObserveOn(this).Subscribe(OnFrameAvailable),
            };

            videoProvider.StartStreaming();
        }
예제 #3
0
        public static IRecorder CreateRecorder()
        {
            if (!NAudioRecorder.GetAvailableDevices().Any())
            {
                Assert.Inconclusive("No available devices for NAudioRecorder.");
            }

            return(new NAudioRecorder());
        }
예제 #4
0
 private void btnStopCapture_Click(object sender, EventArgs e)
 {
     if (this.recorder != null)
     {
         this.recorder.StopRec();
         this.btnCapture.Enabled     = true;
         this.btnStopCapture.Enabled = false;
         this.textFileName.Text      = this.recorder.FileName;
         this.recorder = null;
     }
 }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="recorder"></param>
        /// <param name="settings"></param>
        /// <param name="cancellationToken"></param>
        public static async Task <IRecording> StartWithPlaybackAsync(
            this NAudioRecorder recorder,
            AudioSettings?settings = null,
            CancellationToken cancellationToken = default)
        {
            recorder = recorder ?? throw new ArgumentNullException(nameof(recorder));

            var recording = await recorder.StartAsync(settings, cancellationToken).ConfigureAwait(false);

            return(recording.WithPlayback(settings));
        }
예제 #6
0
        public void SR_Stop()
        {
            //buttonRecord.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("recording");

            if (recorder == null)
            {
                return;
            }
            recorder.StopRec();
            recorder = null;
        }
예제 #7
0
 public void SR_Record(string filePath)
 {
     if (recorder == null)
     {
         recorder = new NAudioRecorder();
     }
     recorder.SetFileName(filePath);
     recorder.StartRec();
     //labelInfo.ForeColor = Color.SpringGreen;
     //labelInfo.Text = "Record: Recording.";
 }
예제 #8
0
        public async Task RealTimePlayRecordTest()
        {
            using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
            var cancellationToken = cancellationTokenSource.Token;

            CheckDevices();

            using var recorder  = new NAudioRecorder();
            using var recording = await recorder.StartWithPlaybackAsync(null, cancellationToken);

            await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
        }
예제 #9
0
        private static void CheckDevices()
        {
            var devices = NAudioRecorder.GetAvailableDevices().ToList();

            if (!devices.Any())
            {
                Assert.Inconclusive("No available devices for NAudioRecorder.");
            }

            Console.WriteLine("Available devices:");
            foreach (var device in devices)
            {
                Console.WriteLine($" - Name: {device.ProductName}, Channels: {device.Channels}");
            }
        }
예제 #10
0
        public async Task Mp3Test()
        {
            using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
            var cancellationToken = cancellationTokenSource.Token;

            CheckDevices();

            using var recorder  = new NAudioRecorder();
            using var recording = await recorder.StartAsync(new AudioSettings (AudioFormat.Mp3), cancellationToken);

            await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);

            var bytes = await recording.StopAsync(cancellationToken);

            Assert.AreNotEqual(0, bytes.Length);
        }
예제 #11
0
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            Dispatcher?.Invoke(() =>
            {
                StartButton.IsEnabled = false;
                StopButton.IsEnabled  = true;
                OutputTextBox.Text   += $"{DateTime.Now:h:mm:ss.fff} Started {Environment.NewLine}";
            });

            try
            {
                using var recorder   = new NAudioRecorder();
                using var recognizer = RecognizerComboBox.Text switch
                      {
                          nameof(YandexRecognizer) => new YandexRecognizer
                          {
                              OAuthToken = OAuthTokenTextBox.Text,
                              FolderId   = FolderIdTextBox.Text,
                              Lang       = "ru-RU",
                          },
                          nameof(WitAiRecognizer) or _ => (IRecognizer) new WitAiRecognizer
                          {
                              Token = !string.IsNullOrWhiteSpace(OAuthTokenTextBox.Text)
                            ? OAuthTokenTextBox.Text
                            : "KATWBG4RQCFNBLQTY6QQUKB2SH6EIELG",
                          },
                      };
                var exceptions = new ExceptionsBag();
                exceptions.ExceptionOccurred += (_, exception) => OnException(exception);

                Recognition = await recognizer.StartStreamingRecognitionAsync(recorder, exceptions).ConfigureAwait(false);

                Recognition.PreviewReceived += (_, value) => Dispatcher?.Invoke(() =>
                {
                    OutputTextBox.Text += $"{DateTime.Now:h:mm:ss.fff} Preview: {value}{Environment.NewLine}";
                });
                Recognition.Stopped += (_, value) => Dispatcher?.Invoke(() =>
                {
                    OutputTextBox.Text += $"{DateTime.Now:h:mm:ss.fff} Final: {value}{Environment.NewLine}";
                });
            }
            catch (Exception exception)
            {
                OnException(exception);
            }
        }
예제 #12
0
        public async Task PlayTest()
        {
            using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
            var cancellationToken = cancellationTokenSource.Token;

            CheckDevices();

            var settings = new AudioSettings();

            using var recorder  = new NAudioRecorder();
            using var player    = new NAudioPlayer();
            using var recording = await recorder.StartAsync(settings, cancellationToken);

            await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);

            var bytes = await recording.StopAsync(cancellationToken);

            await player.PlayAsync(bytes, settings, cancellationToken);
        }
예제 #13
0
        private void btnCapture_Click(object sender, EventArgs e)
        {
            byte mode = 0;

            if (this.radSoundCard.Checked)
            {
                mode = 1;
            }
            this.recorder = new NAudioRecorder(mode, this.updateProgress);
            string path = Application.StartupPath + @"\Capture\";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            this.recorder.FileName = path + String.Format("Audio {0:yyy-MM-dd HH-mm-ss}.wav", DateTime.Now);
            this.recorder.StartRec();
            this.btnStopCapture.Enabled = true;
            this.btnCapture.Enabled     = false;
        }
예제 #14
0
        public async Task SilenceDetectionTest()
        {
            using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
            var cancellationToken = cancellationTokenSource.Token;

            CheckDevices();

            var source = new TaskCompletionSource <bool>();

            using var exceptions   = new ExceptionsBag();
            using var registration = cancellationToken.Register(() => source.TrySetCanceled(cancellationToken));

            using var recorder  = new NAudioRecorder();
            using var recording = await recorder.StartWithPlaybackAsync(null, cancellationToken);

            recording.Stopped += (_, _) => source.TrySetResult(true);
            recording.StopWhenSilence(exceptions: exceptions);

            await source.Task;
        }
예제 #15
0
        private static void StartVoiceAssistant()
        {
            _config = VoiceAssistantConfig.Default();
            _speechRecognizerClient = new WitAiSpeechRecognitionClient(_config.WitAiToken, _config.WitAiTimeoutSeconds);
            _recorder = new NAudioRecorder(_config.SignalPath);

            using (_synth = new SpeechSynthesizer())
            {
                _synth.SetOutputToDefaultAudioDevice();
                using (_recognizer = CreateSimbaCommandRecognizer())
                {
                    _assistant = new Assistant(_config.PluginsPath, TextToSpeech, _config.WordNetPath);
                    _assistant.Start();
                    while (true)
                    {
                        Console.ReadLine();
                    }
                }
            }
        }