Voximplant. Blog

Microphone testing service

Headset

Many Skype users are familiar with its microphone testing service (echo123). When you call the testing service it asks you to say something and records the stream, then it plays it back and if you hear your voice it means that your audio recording device is configured correctly. You can implement similar scenario for your VoxImplant application by using the following VoxEngine scenario:

  1. require(Modules.Recorder);
  2.  
  3. var fileURL, call;
  4.  
  5. VoxEngine.addEventListener(AppEvents.CallAlerting, function (e) {
  6. call = e.call;
  7. e.call.answer();
  8. e.call.addEventListener(CallEvents.Connected, function (e) {
  9.  
  10. call.say("Hello, welcome to VoxImplant testing service." +
  11. "After the beep please record your message," +
  12. "afterwards your message will be played back to you.", Language.UK_ENGLISH_FEMALE);
  13. call.addEventListener(CallEvents.PlaybackFinished, handleIntroPlayed);
  14.  
  15. });
  16. e.call.addEventListener(CallEvents.Disconnected, VoxEngine.terminate);
  17. });
  18.  
  19. function handleIntroPlayed(e) {
  20. call.removeEventListener(CallEvents.PlaybackFinished, handleIntroPlayed);
  21. call.startPlayback("http://cdn.zingaya.com/sounds/beep-1.mp3");
  22. call.addEventListener(CallEvents.PlaybackFinished, handleRecordStart);
  23. }
  24.  
  25. function handleRecordStart(e) {
  26. call.removeEventListener(CallEvents.PlaybackFinished, handleRecordStart);
  27. var rec = VoxEngine.createRecorder();
  28. rec.addEventListener(RecorderEvents.Started, handleRecordingStarted);
  29. rec.addEventListener(RecorderEvents.Stopped, handleRecordingStopped);
  30. e.call.sendMediaTo(rec);
  31. setTimeout(function () {
  32. rec.stop();
  33. }, 6000);
  34. }
  35.  
  36. function handleRecordingStarted(e) {
  37. fileURL = e.url;
  38. }
  39.  
  40. function handleRecordingStopped(e) {
  41. call.startPlayback(fileURL);
  42. call.addEventListener(CallEvents.PlaybackFinished, function (e) {
  43. setTimeout(handleRecordPlayed, 1000);
  44. });
  45. }
  46.  
  47. function handleRecordPlayed() {
  48. call.say("If you were able to hear your own voice, " +
  49. "then you have configured your audio recording device correctly." +
  50. "If you hear this message but not your own voice then you need to configure" +
  51. " your audio recording device. Goodbye.", Language.UK_ENGLISH_FEMALE);
  52. call.addEventListener(CallEvents.PlaybackFinished, function (e) {
  53. VoxEngine.terminate();
  54. });
  55. }

Tagged in , , ,

Comments