コード例 #1
0
        async Task RecordAudio()
        {
            try
            {
                if (!recorder.IsRecording)
                {
                    recorder.StopRecordingOnSilence = TimeoutSwitch.On;

                    RecordButton.Enabled = false;
                    PlayButton.Enabled   = false;

                    //the returned Task here will complete once recording is finished
                    var recordTask = await recorder.StartRecording();

                    RecordButton.SetTitle("Stop", UIControlState.Normal);
                    RecordButton.Enabled = true;

                    var audioFile = await recordTask;

                    //audioFile will contain the path to the recorded audio file

                    RecordButton.SetTitle("Record", UIControlState.Normal);
                    PlayButton.Enabled = !string.IsNullOrEmpty(audioFile);
                }
                else
                {
                    RecordButton.Enabled = false;

                    await recorder.StopRecording();

                    RecordButton.SetTitle("Record", UIControlState.Normal);
                    RecordButton.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                //blow up the app!
                throw ex;
            }
        }
コード例 #2
0
        async Task RecordAudio()
        {
            try
            {
                if (!recorder.IsRecording) //Record button clicked
                {
                    RecordButton.IsEnabled = false;

                    PlayButton.IsEnabled = false;

                    //start recording audio

                    var audioRecordTask = await recorder.StartRecording();

                    RecordButton.Text = "Закончить запись";

                    RecordButton.IsEnabled = true;
                    await audioRecordTask;

                    RecordButton.Text    = "Начать запись";
                    PlayButton.IsEnabled = true;
                }

                else //Stop button clicked
                {
                    RecordButton.IsEnabled = false;
                    //stop the recording...
                    await recorder.StopRecording();

                    RecordButton.IsEnabled = true;
                    await PlayAudio();
                }
            }

            catch (Exception ex)
            {
                //blow up the app!
                throw ex;
            }
        }
コード例 #3
0
        async Task RecordAudio()
        {
            try
            {
                if (!recorder.IsRecording) //Record button clicked
                {
                    recorder.StopRecordingOnSilence = TimeoutSwitch.IsToggled;

                    RecordButton.IsEnabled = false;
                    PlayButton.IsEnabled   = false;

                    //start recording audio
                    var audioRecordTask = await recorder.StartRecording();

                    //RecordButton.Text = "Stop Recording";
                    RecordButton.Image     = "StopRecording.png";
                    RecordButton.IsEnabled = true;

                    await audioRecordTask;

                    //RecordButton.Text = "Record";
                    PlayButton.IsEnabled = true;
                }
                else //Stop button clicked
                {
                    RecordButton.IsEnabled = false;
                    RecordButton.Image     = "Audio.png";
                    //stop the recording...
                    await recorder.StopRecording();

                    RecordButton.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                //blow up the app!
                throw ex;
            }
        }
コード例 #4
0
        async void Button_Clicked(System.Object sender, System.EventArgs e)
        {
            // This was not in the video, we need to ask permission
            // for the microphone to make it work for Android, see https://youtu.be/uBdX54sTCP0
            var status = await Permissions.RequestAsync <Permissions.Microphone>();

            if (status != PermissionStatus.Granted)
            {
                return;
            }

            if (audioRecorderService.IsRecording)
            {
                await audioRecorderService.StopRecording();

                audioPlayer.Play(audioRecorderService.GetAudioFilePath());
            }
            else
            {
                await audioRecorderService.StartRecording();
            }
        }
コード例 #5
0
        async void Gravar_Clicked(object sender, EventArgs e)
        {
            try
            {
                if (!gravador.IsRecording)
                {
                    gravador.StopRecordingOnSilence = TimeoutSwitch.IsToggled;

                    GravarButton.IsEnabled     = false;
                    ReproduzirButton.IsEnabled = false;

                    //Começa gravação
                    var audioRecordTask = await gravador.StartRecording();

                    GravarButton.Text      = "Parar Gravação";
                    GravarButton.IsEnabled = true;

                    await audioRecordTask;

                    GravarButton.Text          = "Gravar";
                    ReproduzirButton.IsEnabled = true;
                }
                else
                {
                    GravarButton.IsEnabled = false;

                    //parar a gravação...
                    await gravador.StopRecording();

                    GravarButton.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                //blow up the app!
                await DisplayAlert("Erro", ex.Message, "OK");
            }
        }
コード例 #6
0
ファイル: SayItPage.xaml.cs プロジェクト: BeaumerF/2doo
        async Task RecordAudio()
        {
            try
            {
                if (!recorder.IsRecording) //Record button clicked
                {
                    //start recording audio
                    var audioRecordTask = await recorder.StartRecording();

                    var audioFile = await audioRecordTask;

                    //if we're not streaming the audio as we're recording, we'll use the file-based STT API here
                    if (audioFile != null)
                    {
                        var resultText = await bingSpeechClient.SpeechToTextSimple(audioFile);

                        if ((ResultsLabel.Text = resultText.DisplayText) != null)
                        {
                            var splitText = resultText.DisplayText.Split(new[] { ' ' }, 3);
                            if (splitText.Length == 3)
                            {
                                await DoCommands(splitText, resultText.DisplayText);
                            }
                        }
                    }
                }
                else //Stop button clicked
                {
                    //stop the recording...
                    await recorder.StopRecording();
                }
            }
            catch (Exception ex)
            {
                //blow up the app!
                throw ex;
            }
        }
コード例 #7
0
        async Task RecordAudio()
        {
            try
            {
                if (!recorder.IsRecording)                 //Record button clicked
                {
                    UpdateUI(false);

                    //start recording audio
                    var audioRecordTask = await recorder.StartRecording();

                    UpdateUI(true, "Stop");

                    //set the selected recognition mode & profanity mode
                    speechClient.RecognitionMode = RecognitionMode;
                    speechClient.ProfanityMode   = ProfanityMode;

                    //if we want to stream the audio as it's recording, we'll do that below
                    if (StreamSwitch.IsToggled)
                    {
                        //does nothing more than turn the spinner on once recording is complete
                        _ = audioRecordTask.ContinueWith((audioFile) => UpdateUI(false, "Record", true), TaskScheduler.FromCurrentSynchronizationContext());

                        //do streaming speech to text
                        var resultText = await SpeechToText(audioRecordTask);

                        ResultsLabel.Text = resultText ?? "No Results!";

                        UpdateUI(true, "Record", false);
                    }
                    else                     //waits for the audio file to finish recording before starting to send audio data to the server
                    {
                        var audioFile = await audioRecordTask;

                        UpdateUI(true, "Record", true);

                        //if we're not streaming the audio as we're recording, we'll use the file-based STT API here
                        if (audioFile != null)
                        {
                            var resultText = await SpeechToText(audioFile);

                            ResultsLabel.Text = resultText ?? "No Results!";
                        }

                        UpdateUI(true, false);
                    }
                }
                else                 //Stop button clicked
                {
                    UpdateUI(false, true);

                    //stop the recording...
                    await recorder.StopRecording();
                }
            }
            catch (Exception ex)
            {
                ResultsLabel.Text = ProcessResult(ex);

                UpdateUI(true, "Record", false);
            }
        }
コード例 #8
0
ファイル: Recorder.cs プロジェクト: andru196/GuideOne_Xamarin
 async void OnPauseButtonClicked(object sender, EventArgs e)
 {
     PageState = MainPageStatus.PauseRecord;
     await _audioRecorderService.StopRecording();
 }
コード例 #9
0
        async Task RecordAudio()
        {
            try
            {
                if (!recorder.IsRecording)                 //Record button clicked
                {
                    updateUI(false);

                    //start recording audio
                    var audioRecordTask = await recorder.StartRecording();

                    updateUI(true, "Stop");

                    //configure the Bing Speech client
                    var recognitionMode = (RecognitionMode)Enum.Parse(typeof(RecognitionMode), RecognitionModePicker.SelectedItem.ToString());
                    var profanityMode   = (ProfanityMode)Enum.Parse(typeof(ProfanityMode), ProfanityModePicker.SelectedItem.ToString());
                    outputMode = (OutputMode)Enum.Parse(typeof(OutputMode), OutputModePicker.SelectedItem.ToString());

                    //set the selected recognition mode & profanity mode
                    bingSpeechClient.RecognitionMode = recognitionMode;
                    bingSpeechClient.ProfanityMode   = profanityMode;

                    //if we want to stream the audio as it's recording, we'll do that below
                    if (StreamSwitch.IsToggled)
                    {
                        //does nothing more than turn the spinner on once recording is complete
                        _ = audioRecordTask.ContinueWith((audioFile) => updateUI(false, "Record", true), TaskScheduler.FromCurrentSynchronizationContext());

                        //do streaming speech to text
                        var resultText = await SpeechToText(audioRecordTask);

                        ResultsLabel.Text = resultText ?? "No Results!";

                        updateUI(true, "Record", false);
                    }
                    else                     //waits for the audio file to finish recording before starting to send audio data to the server
                    {
                        var audioFile = await audioRecordTask;

                        updateUI(true, "Record", true);

                        //if we're not streaming the audio as we're recording, we'll use the file-based STT API here
                        if (audioFile != null)
                        {
                            var resultText = await SpeechToText(audioFile);

                            ResultsLabel.Text = resultText ?? "No Results!";
                        }

                        updateUI(true, false);
                    }
                }
                else                 //Stop button clicked
                {
                    updateUI(false, true);

                    //stop the recording...
                    await recorder.StopRecording();
                }
            }
            catch (Exception ex)
            {
                //blow up the app!
                throw ex;
            }
        }
コード例 #10
0
 async void Stop_Clicked(object sender, EventArgs e)
 {
     StopRecording();
     await recorder.StopRecording();
 }
コード例 #11
0
 public Task StopRecordingAsync() => recorder.StopRecording();
コード例 #12
0
        public HomeViewModel()
        {
            GenreList      = new ObservableRangeCollection <Genre>();
            PredictedLabel = "Genre";
            var entries = new[]
            {
                new ChartEntry(212)
                {
                    Label      = "What will it be?",
                    ValueLabel = "212",
                    Color      = SKColor.Parse("#2c3e50")
                }
            };

            CurrentChart = new DonutChart()
            {
                Entries = entries, IsAnimated = true, AnimationDuration = TimeSpan.FromSeconds(5)
            };
            AggChart = new DonutChart()
            {
                Entries = entries, IsAnimated = true, AnimationDuration = TimeSpan.FromSeconds(5)
            };
            recorder = new AudioRecorderService
            {
                StopRecordingOnSilence    = false,                   //will stop recording after 2 seconds (default)
                StopRecordingAfterTimeout = true,                    //stop recording after a max timeout (defined below)
                TotalAudioTimeout         = TimeSpan.FromSeconds(30) //audio will stop recording after 15 seconds
            };
            //player = new AudioPlayer();
            playCommand = new Command(() =>
            {
                var files = Assembly.GetExecutingAssembly().GetManifestResourceNames();
                Console.WriteLine($"AUDXAM ALL FILES: {files.Length} {files.ToList()} { files[0]}");
                if (recorder.IsRecording != true && player.IsPlaying == false)
                {
                    //player.Load(GetStreamFromFile());
                    player.Play();
                    var startTimeSpan  = TimeSpan.Zero;
                    var periodTimeSpan = TimeSpan.FromMilliseconds(60);
                    float[] op2        = new float[10];
                    Array.Clear(op2, 0, op2.Length);
                    timer = new System.Threading.Timer((e) =>
                    {
                        if (player.IsPlaying)
                        {
                            //Console.WriteLine($"{tag} CURRENT PREDICTION: {op.Score[9]} curPos:{Convert.ToInt32(player.CurrentPosition)} M AT ZERO {featureTimeList[0].Mfcc0} AT FIVE {featureTimeList[5].Mfcc0} FINAL -> {ConsumeModel.Predict(featureTimeList[Convert.ToInt32(player.CurrentPosition)]).Score[5]}");
                            op = featureTimeList[Convert.ToInt32(player.CurrentPosition)];

                            for (int i = 0; i < 10; i++)
                            {
                                op2[i] += op[i];
                            }

                            float max_sf    = 0;
                            int max_ind     = 0;
                            string[] labels = "Blues, Classical, Country, Disco, HipHop, Jazz, Metal, Pop, Reggae Rock".Split(',');
                            for (int i = 0; i < 10; i++)
                            {
                                if (op2[i] > max_sf)
                                {
                                    max_sf  = op2[i];
                                    max_ind = i;
                                }
                            }

                            PredictedLabel = $"{labels[max_ind]}!";

                            //Pass to ML.net

                            var entries_agg = new[]
                            {
                                new ChartEntry(op2[0])
                                {
                                    Label      = "Blues",
                                    ValueLabel = $"{op2[0]}",
                                    Color      = SKColor.Parse("#2c3e50")
                                },
                                new ChartEntry(op2[1])
                                {
                                    Label      = "Classical",
                                    ValueLabel = $"{op2[1]}",
                                    Color      = SKColor.Parse("#77d065")
                                },
                                new ChartEntry(op2[2])
                                {
                                    Label      = "Country",
                                    ValueLabel = $"{op2[2]}",
                                    Color      = SKColor.Parse("#b455b6")
                                },
                                new ChartEntry(op2[3])
                                {
                                    Label      = "Disco",
                                    ValueLabel = $"{op2[3]}",
                                    Color      = SKColor.Parse("#245e50")
                                },
                                new ChartEntry(op2[4])
                                {
                                    Label      = "Hiphop",
                                    ValueLabel = $"{op2[4]}",
                                    Color      = SKColor.Parse("#3498db")
                                },
                                new ChartEntry(op2[5])
                                {
                                    Label      = "Jazz",
                                    ValueLabel = $"{op2[5]}",
                                    Color      = SKColor.Parse("#263e50")
                                },
                                new ChartEntry(op2[6])
                                {
                                    Label      = "Metal",
                                    ValueLabel = $"{op2[6]}",
                                    Color      = SKColor.Parse("#123456")
                                },
                                new ChartEntry(op2[7])
                                {
                                    Label      = "Pop",
                                    ValueLabel = $"{op2[7]}",
                                    Color      = SKColor.Parse("#654321")
                                },
                                new ChartEntry(op2[8])
                                {
                                    Label      = "Reggae",
                                    ValueLabel = $"{op2[8]}",
                                    Color      = SKColor.Parse("#526784")
                                },
                                new ChartEntry(op2[9])
                                {
                                    Label      = "Rock",
                                    ValueLabel = $"{op2[9]}",
                                    Color      = SKColor.Parse("#404040")
                                }
                            };



                            var entries_current = new[]
                            {
                                new ChartEntry(op[0])
                                {
                                    Label      = "Blues",
                                    ValueLabel = $"{op[0]}",
                                    Color      = SKColor.Parse("#2c3e50")
                                },
                                new ChartEntry(op[1])
                                {
                                    Label      = "Classical",
                                    ValueLabel = $"{op[1]}",
                                    Color      = SKColor.Parse("#77d065")
                                },
                                new ChartEntry(op[2])
                                {
                                    Label      = "Country",
                                    ValueLabel = $"{op[2]}",
                                    Color      = SKColor.Parse("#b455b6")
                                },
                                new ChartEntry(op[3])
                                {
                                    Label      = "Disco",
                                    ValueLabel = $"{op[3]}",
                                    Color      = SKColor.Parse("#245e50")
                                },
                                new ChartEntry(op[4])
                                {
                                    Label      = "Hiphop",
                                    ValueLabel = $"{op[4]}",
                                    Color      = SKColor.Parse("#3498db")
                                },
                                new ChartEntry(op[5])
                                {
                                    Label      = "Jazz",
                                    ValueLabel = $"{op[5]}",
                                    Color      = SKColor.Parse("#263e50")
                                },
                                new ChartEntry(op[6])
                                {
                                    Label      = "Metal",
                                    ValueLabel = $"{op[6]}",
                                    Color      = SKColor.Parse("#123456")
                                },
                                new ChartEntry(op[7])
                                {
                                    Label      = "Pop",
                                    ValueLabel = $"{op[7]}",
                                    Color      = SKColor.Parse("#654321")
                                },
                                new ChartEntry(op[8])
                                {
                                    Label      = "Reggae",
                                    ValueLabel = $"{op[8]}",
                                    Color      = SKColor.Parse("#526784")
                                },
                                new ChartEntry(op[9])
                                {
                                    Label      = "Rock",
                                    ValueLabel = $"{op[9]}",
                                    Color      = SKColor.Parse("#404040")
                                }
                            };

                            //Update and draw graph
                            AggChart = new DonutChart()
                            {
                                Entries = entries_agg, IsAnimated = false, AnimationDuration = TimeSpan.FromMilliseconds(0)
                            };
                            //CurrentChart = new DonutChart() { Entries = entries_current, IsAnimated = false, AnimationDuration = TimeSpan.FromMilliseconds(0) };
                            //Console.WriteLine($"{tag} Updated chart! C {op.Score[9]} A ->{op2[9]}");

                            //Graph 1 -> Current prediciton

                            //Graph 2 -> Aggregate of predictions so far
                        }
                        else
                        {
                            player.Seek(0.0);
                            timer.Dispose();
                        }
                    }, null, startTimeSpan, periodTimeSpan);
                }
            });

            recordCommand = new Command(async() =>
            {
                if (RecordStatus != "record")
                {
                    PredictedLabel = "Processing audio...";
                    await recorder.StopRecording().ConfigureAwait(true);
                    if (_filePath != null)
                    {
                        //await extractFeatures();
                        var stream = new FileStream(_filePath, FileMode.Open);
                        AudioFunctions.WriteWavHeader(stream, 1, 48000, 16, (int)stream.Length - 44);
                        stream.Close();
                        player.Load(GetStreamFromFile());
                        //player.Play();
                        duration = Convert.ToInt32(player.Duration);
                        Console.WriteLine($"{tag} DUR: {duration}");
                        // player.Dispose();
                        extractFeatures();
                        //await predict
                    }
                    RecordStatus = "record";
                }
                else
                {
                    PredictedLabel = "Recording...";
                    IsBusy         = true;
                    RecordStatus   = "stop";
                    var recordTask = await recorder.StartRecording().ConfigureAwait(true);
                    _filePath      = await recordTask.ConfigureAwait(true);
                    //player.Play(_filePath
                }
            });
        }
コード例 #13
0
ファイル: AddPage.xaml.cs プロジェクト: luismts/FancyToDoList
        void OnRecognizeSpeechButtonClicked(object sender, EventArgs e)
        {
            var x = audioRecordingService;

            Device.BeginInvokeOnMainThread(async() => {
                try
                {
                    Task <string> audioRecordTask = null;
                    if (!audioRecordingService.IsRecording)
                    {
                        audioRecordTask = await audioRecordingService.StartRecording();

                        activityIndicator.IsVisible = true;

                        spellsheckButton.IsEnabled  = false;
                        translationButton.IsEnabled = false;

                        ((Button)sender).Image = "record.png";
                    }
                    else
                    {
                        await audioRecordingService.StopRecording();

                        ((Button)sender).Image = "recording.png";
                    }

                    //isRecording = !isRecording;
                    if (!audioRecordingService.IsRecording)
                    {
                        var audioFile = await audioRecordTask;

                        if (audioFile == null)
                        {
                            return;
                        }

                        var speechResult = await bingSpeechService.RecognizeSpeechAsync(audioFile, Constants.TextTranslatorApiKey);
                        Debug.WriteLine("Name: " + speechResult.DisplayText);
                        Debug.WriteLine("Recognition Status: " + speechResult.RecognitionStatus);

                        if (!string.IsNullOrWhiteSpace(speechResult.DisplayText))
                        {
                            Context.Item.Description = char.ToUpper(speechResult.DisplayText[0]) + speechResult.DisplayText.Substring(1);
                            OnPropertyChanged("TodoItem");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
                finally
                {
                    if (!audioRecordingService.IsRecording)
                    {
                        //((Button)sender).Image = "record.png";

                        activityIndicator.IsVisible = false;
                        spellsheckButton.IsEnabled  = true;
                        translationButton.IsEnabled = true;
                    }
                }
            });
        }
コード例 #14
0
 public async Task Stop()
 {
     await Recorder.StopRecording(false);
 }
コード例 #15
0
        async Task RecordAudio()
        {
            try
            {
                if (!recorder.IsRecording) //Record button clicked
                {
                    recorder.StopRecordingOnSilence = TimeoutSwitch.IsToggled;

                    RecordButton.IsEnabled = false;
                    // PlayButton.IsEnabled = true;

                    //start recording audio
                    var audioRecordTask = await recorder.StartRecording();

                    RecordButton.Text      = "Stop Recording";
                    RecordButton.IsEnabled = true;

                    await audioRecordTask;

                    //RecordButton.Text = "Record";
                    // PlayButton.IsEnabled = true;
                }
                else //Stop button clicked
                {
                    RecordButton.IsEnabled = false;

                    recorder.StopRecording();

                    RecordButton.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }


            var filePath = recorder.GetAudioFilePath();
            var length   = filePath.Length.ToString();

            //ArchivoAudioModel model = new ArchivoAudioModel();
            //model.audio = filePath;
            //model.Idpostulante = 2;
            //model.idRequerimiento = 1;
            //model.idListPregunta = ListPreguntaDet.idListPregunta;
            //model.idPregunta = ListPreguntaDet.idPregunta;


            //    HttpContent fileStreamContent = new StreamContent(filePath.);

            var           content       = new MultipartFormDataContent();
            FileStream    fs            = File.OpenRead(filePath);
            StreamContent streamContent = new StreamContent(fs);

            streamContent.Headers.Add("Content-Type", "audio/wav");
            streamContent.Headers.Add("Content-Disposition", "form-data; name=\"file\"; filename=\"" + Path.GetFileName(filePath) + "\"");

            content.Add(streamContent, "file", Path.GetFileName(filePath));
            HttpClient cliente = new HttpClient();
            var        uploadServiceBaseAddress = Servicio.IP + "Upload/Sonidos";
            var        httpResponseMessage      = await cliente.PostAsync(uploadServiceBaseAddress, content);

            var result = await httpResponseMessage.Content.ReadAsStringAsync();

            fs.Close();

            /*METODO PARA GUARDAR EL NOMBRE AUDIO EN LA BASE DE DATOS Y
             * REGISTRAR QUE SE GRABO EL AUDIO CON ESTE POST */

            await DisplayAlert("Aviso", "Guardado", "Aceptar");
        }
コード例 #16
0
        public MainPage()
        {
            recorder.TotalAudioTimeout      = TimeSpan.FromSeconds(15);
            recorder.StopRecordingOnSilence = false;
            recorder.AudioInputReceived    += Recorder_AudioInputReceived;

            InitializeComponent();
            this.btnStart.Clicked += async(s, e) =>
            { if (!recorder.IsRecording)
              {
                  this.btnStop.IsEnabled = true;
                  DependencyService.Get <IAudio>().PlayAndRecord();
                  await recorder.StartRecording();
              }
            };
            this.btnStop.Clicked += async(s, e) => { if (recorder.IsRecording)
                                                     {
                                                         await recorder.StopRecording();
                                                     }
            };
            this.btnPlay.Clicked += (s, e) =>
            {
                filePath = recorder.GetAudioFilePath();
                Console.WriteLine(filePath);
                player.Play(filePath);
            };
            this.player.FinishedPlaying += async(s, e) =>
            {
                filePath = recorder.GetAudioFilePath();
                if (!string.IsNullOrEmpty(filePath))
                {
                    this.btnStart.IsEnabled       = true;
                    this.btnStart.BackgroundColor = Color.FromHex("#7cbb45");
                    this.btnPlay.IsEnabled        = true;
                    this.btnPlay.BackgroundColor  = Color.FromHex("#7cbb45");
                    this.btnStop.IsEnabled        = false;
                    this.btnStop.BackgroundColor  = Color.Silver;
                }
                else
                {
                    await DisplayAlert("Info", "No audio to play", "OK");
                }
            };
            this.btnPlayFromServer.Clicked += async(s, e) =>
            {
                var uri = "http://10.0.0.241/FileUploadDownload/api/FileUpload/audio";
                using (var client = new HttpClient())
                {
                    this.btnPlayFromServer.BackgroundColor = Color.Blue;
                    var response = await client.GetAsync(uri);

                    if (response.IsSuccessStatusCode)
                    {
                        var content = await response.Content.ReadAsStreamAsync();

                        var x = await CrossMediaManager.Current.Play(content, "audio.wav");
                    }



                    this.btnPlayFromServer.BackgroundColor = Color.Red;
                }
            };
        }