/// <summary> /// Initialization constructor for the verify speaker page /// </summary> public VerifySpeakerPage() { InitializeComponent(); try { _subscriptionKey = ((MainWindow)Application.Current.MainWindow).SubscriptionKey; IsolatedStorageHelper _storageHelper = IsolatedStorageHelper.getInstance(); string _savedSpeakerId = _storageHelper.readValue(MainWindow.SPEAKER_FILENAME); if (_savedSpeakerId != null) { _speakerId = new Guid(_savedSpeakerId); } if (_speakerId == Guid.Empty) { ((MainWindow)Application.Current.MainWindow).Log("You need to create a profile and complete enrollments first before verification"); recordBtn.IsEnabled = false; stopRecordBtn.IsEnabled = false; } else { initializeRecorder(); _serviceClient = new SpeakerVerificationServiceClient(_subscriptionKey); string userPhrase = _storageHelper.readValue(MainWindow.SPEAKER_PHRASE_FILENAME); userPhraseTxt.Text = userPhrase; stopRecordBtn.IsEnabled = false; } } catch (Exception gexp) { setStatus("Error: " + gexp.Message); recordBtn.IsEnabled = false; stopRecordBtn.IsEnabled = false; } }
public async void verifySpeaker(byte[] data, string profilename) { try { SpeakerVerificationServiceClient _serviceClient = new SpeakerVerificationServiceClient("7afe1cdfee8243c0aca9fadc7d42f978"); Guid _speakerId = Guid.Empty; using (Stream audioStream = new MemoryStream(data)) { Verification response = await _serviceClient.VerifyAsync(audioStream, _speakerId); if (response.Result == Result.Accept) { TextBox1.Text = "Accept"; } else { TextBox1.Text = "Rejected"; } } } catch (Exception ex) { throw ex; } }
private async Task <bool> SpeakerVerificationAsync(CancellationToken ct, Guid speakerProfileID, string verificationPhrase) { // Prompt the user to record an audio stream of their phrase var audioStream = await this.PromptUserForVoicePhraseAsync(ct, verificationPhrase); try { // Use the Speaker Verification API nuget package to access to the Cognitive Services Speaker Verification service var client = new SpeakerVerificationServiceClient(App.SPEAKER_RECOGNITION_API_SUBSCRIPTION_KEY); // Pass the audio stream and the user's profile ID to the service to have analyzed for match var response = await client.VerifyAsync(audioStream, speakerProfileID); // Check to see if the stream was accepted and then the confidence level Cognitive Services has that the speaker is a match to the profile specified if (response.Result == Microsoft.ProjectOxford.SpeakerRecognition.Contract.Verification.Result.Accept) { return(response.Confidence >= Microsoft.ProjectOxford.SpeakerRecognition.Contract.Confidence.Normal); } else { return(false); } } catch (Exception ex) { Debug.WriteLine("Error during SpeakerVerificationAsync: " + ex.ToString()); return(false); } }
/// <summary> /// Creates a new EnrollPage /// </summary> /// <param name="subscriptionKey">The subscription key</param> public EnrollPage() { InitializeComponent(); _subscriptionKey = ((MainWindow)Application.Current.MainWindow).SubscriptionKey; _serviceClient = new SpeakerVerificationServiceClient(_subscriptionKey); initializeRecorder(); initializeSpeaker(); }
private async void OnButtonClicked(object sender, RoutedEventArgs e) { if (!_recording) { MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings { StreamingCaptureMode = StreamingCaptureMode.Audio }; _capture = new MediaCapture(); await _capture.InitializeAsync(settings); _capture.RecordLimitationExceeded += async(MediaCapture s) => { await new MessageDialog("Record limtation exceeded", "Error").ShowAsync(); }; _capture.Failed += async(MediaCapture s, MediaCaptureFailedEventArgs args) => { await new MessageDialog("Media capture failed: " + args.Message, "Error").ShowAsync(); }; _buffer = new InMemoryRandomAccessStream(); var profile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.Auto); profile.Audio = AudioEncodingProperties.CreatePcm(16000, 1, 16); // Must be mono (1 channel) await _capture.StartRecordToStreamAsync(profile, _buffer); TheButton.Content = "Verify"; _recording = true; } else // Recording { if (_capture != null && _buffer != null && _id != null && _id != Guid.Empty) { await _capture.StopRecordAsync(); IRandomAccessStream stream = _buffer.CloneStream(); var client = new SpeakerVerificationServiceClient(_key); var response = await client.VerifyAsync(stream.AsStream(), _id); string message = String.Format("Result: {0}, Confidence: {1}", response.Result, response.Confidence); await new MessageDialog(message).ShowAsync(); _capture.Dispose(); _capture = null; _buffer.Dispose(); _buffer = null; } TheButton.Content = "Start"; _recording = false; } }
public MainWindow() { try { InitializeComponent(); verServiceClient = new SpeakerVerificationServiceClient(speakerSubscriptionAPIKey); initializeRecorder(); initializeSpeaker(); } catch (Exception ex) { Console.WriteLine("Error : " + ex.Message); } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); // Get the speaker profile var client = new SpeakerVerificationServiceClient(_key); var profiles = await client.GetProfilesAsync(); if (profiles.Length == 0) { await new MessageDialog("No speaker profiles found for this subscription", "Error").ShowAsync(); return; } _id = profiles[0].ProfileId; }
/// <summary> /// Creates a new EnrollPage /// </summary> /// <param name="subscriptionKey">The subscription key</param> public EnrollPage() { try { InitializeComponent(); _subscriptionKey = ((MainWindow)Application.Current.MainWindow).SubscriptionKey; _serviceClient = new SpeakerVerificationServiceClient(_subscriptionKey); initializeRecorder(); initializeSpeaker(); } catch (Exception gexp) { setStatus("Error: " + gexp.Message); record.IsEnabled = false; resetBtn.IsEnabled = false; } }
public MainPage() { this.InitializeComponent(); CaptureMedia = null; _etimer = new DispatcherTimer(); _etimer.Interval = new TimeSpan(0, 0, 10); _etimer.Tick += EnrollmentTime_Over; _vtimer = new DispatcherTimer(); _vtimer.Interval = new TimeSpan(0, 0, 10); _vtimer.Tick += VerificationTime_Over; _subscriptionKey = "put_your_subscription_key_here"; _serviceClient = new SpeakerVerificationServiceClient(_subscriptionKey); }
public LoginWithSpeakerRecognition(string username) { try { InitializeComponent(); dataContext = new UserTableDataContext(); this.username = username; label1.Content = "Hello " + username; user = dataContext.Users.SingleOrDefault(x => x.username == this.username); if (user == null || user.speakerguid == null) { //Delay 2 seconds to check whether user exists or not var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(2) }; timer.Start(); timer.Tick += (sender, args) => { timer.Stop(); MessageBox.Show("User or Voice data is not found", "Error", MessageBoxButton.OK); MainWindow mw = new MainWindow(); mw.Show(); this.Close(); return; }; } else { string _savedSpeakerId = user.speakerguid; if (_savedSpeakerId != null) { _speakerId = new Guid(_savedSpeakerId); } initializeRecorder(); txtPhraseText.Text = user.speakerphrase; _serviceClient = new SpeakerVerificationServiceClient(_subscriptionKey); } } catch (Exception gexp) { MessageBox.Show("Error: " + gexp.Message, "Error", MessageBoxButton.OK); btnRecord.IsEnabled = false; } }
public UserRegistrationAudio(string username) { InitializeComponent(); try { InitializeComponent(); this.username = username; dataContext = new UserTableDataContext(); user = dataContext.Users.SingleOrDefault(x => x.username == this.username); _serviceClient = new SpeakerVerificationServiceClient(_subscriptionKey); initializeRecorder(); initializeSpeaker(); } catch (Exception gexp) { MessageBox.Show("Error: " + gexp.Message, "Error", MessageBoxButton.OK); btnRecord.IsEnabled = false; btnReset.IsEnabled = false; } }
private async void verifySpeaker(Stream audioStream) { try { conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "Select VerifyId, Phrase From AuthenticationDetails where AccountNo = '" + accountNo + "'"; dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { verificationId = dr.GetGuid(0); userPhrase = dr[1].ToString(); Console.WriteLine("Verification Id is : " + verificationId); Console.WriteLine("User Phrase is :" + userPhrase); } } dr.Close(); conn.Close(); //verificationId = Guid.Parse("6c3a49ee-aa36-4a45-b7de-068cd96516bc"); SpeakerVerificationServiceClient verServiceClient = new SpeakerVerificationServiceClient(speakerAPISubscriptionKey); Title = String.Format("Verifying...."); Console.WriteLine("Verifying...."); Verification response = await verServiceClient.VerifyAsync(audioStream, verificationId); Title = String.Format("Verification Done."); Console.WriteLine("Verrification Done."); //statusResTxt.Text = response.Result.ToString(); //confTxt.Text = response.Confidence.ToString(); Console.WriteLine("Response Result is : " + response.Result.ToString()); Console.WriteLine("Response Confidence is : " + response.Confidence.ToString()); if (response.Result == Result.Accept) { //statusResTxt.Background = Brushes.Green; //statusResTxt.Foreground = Brushes.White; speechSynthesizer.SpeakAsync("Hi."); speechSynthesizer.SpeakAsync(_identificationResultTxtBlk.Text.ToString()); speechSynthesizer.SpeakAsync("Thanks to verify your face and voice."); speechSynthesizer.SpeakAsync("Now you can do your transactions"); //return; } else { //statusResTxt.Background = Brushes.Red; //statusResTxt.Foreground = Brushes.White; speechSynthesizer.SpeakAsync("Sorry verification failed."); speechSynthesizer.SpeakAsync("Please speak correct phrase."); return; } } catch (VerificationException exception) { Console.WriteLine("Cannot verify speaker: " + exception.Message); } catch (Exception ex) { Console.WriteLine("Error : " + ex.Message); } }
public VerificationController() { serviceClient = new SpeakerVerificationServiceClient(Keys.subscriptionKey); }
public SpeakerVerificationService(string subscriptionKey) { serviceClient = new SpeakerVerificationServiceClient(subscriptionKey); }
public HomeController(IConfiguration config, SpeakerVerificationServiceClient client) { this.config = config; this.client = client; }