Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AbstractTranscriptionService.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Abstract class representing an interface to implement a speech-to-text
  3. * service on.
  4. */
  5. export default class TranscriptionService {
  6. /**
  7. * Abstract class representing an interface to implement a speech-to-text
  8. * service on.
  9. */
  10. constructor() {
  11. throw new Error('TranscriptionService is abstract and cannot be created');
  12. }
  13. /**
  14. * This method can be used to send the recorder audio stream and
  15. * retrieve the answer from the transcription service from the callback
  16. *
  17. * @param {RecordingResult} recordingResult a recordingResult object which
  18. * includes the recorded audio stream as a blob
  19. * @param {Function} callback which will retrieve the a RecordingResult with
  20. * the answer as a WordArray
  21. */
  22. send(recordingResult, callback) {
  23. this.sendRequest(recordingResult.blob, response => {
  24. if (this.verify(response)) {
  25. recordingResult.wordArray = this.formatResponse(response);
  26. } else {
  27. console.log('the retrieved response from the server is not valid!');
  28. recordingResult.wordArray = [];
  29. }
  30. callback(recordingResult);
  31. });
  32. }
  33. /**
  34. * Abstract method which will rend the recorder audio stream to the implemented
  35. * transcription service and will retrieve an answer, which will be
  36. * called on the given callback method
  37. *
  38. * @param {Blob} audioBlob the recorded audio stream as a single Blob
  39. * @param {function} callback function which will retrieve the answer
  40. * from the service
  41. */
  42. sendRequest(audioBlob, callback) { // eslint-disable-line no-unused-vars
  43. throw new Error('TranscriptionService.sendRequest is abstract');
  44. }
  45. /**
  46. * Abstract method which will parse the output from the implemented
  47. * transcription service to the expected format
  48. *
  49. * The transcriber class expect an array of word objects, where each word
  50. * object is one transcribed word by the service.
  51. *
  52. * The expected output of this method is an array of word objects, in
  53. * the correct order. That is, the first object in the array is the first word
  54. * being said, and the last word in the array is the last word being said
  55. *
  56. * @param response the answer from the speech-to-text server which needs to be
  57. * formatted
  58. * @return {Array<Word>} an array of Word objects
  59. */
  60. formatResponse(response) { // eslint-disable-line no-unused-vars
  61. throw new Error('TranscriptionService.format is abstract');
  62. }
  63. /**
  64. * Abstract method which will verify that the response from the server is valid
  65. *
  66. * @param response the response from the server
  67. * @return {boolean} true if response is valid, false otherwise
  68. */
  69. verify(response) { // eslint-disable-line no-unused-vars
  70. throw new Error('TranscriptionService.verify is abstract');
  71. }
  72. }