spoken-language-identification.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /** @typedef {import('./types').SpokenLanguageIdentificationConfig} SpokenLanguageIdentificationConfig */
  2. /** @typedef {import('./types').SpokenLanguageIdentificationHandle} SpokenLanguageIdentificationHandle */
  3. /** @typedef {import('./non-streaming-asr').OfflineStream} OfflineStream */
  4. const addon = require('./addon.js');
  5. const non_streaming_asr = require('./non-streaming-asr.js');
  6. class SpokenLanguageIdentification {
  7. /**
  8. * @param {SpokenLanguageIdentificationConfig} config
  9. */
  10. constructor(config) {
  11. this.handle = addon.createSpokenLanguageIdentification(config);
  12. this.config = config;
  13. }
  14. /**
  15. * @returns {OfflineStream}
  16. */
  17. createStream() {
  18. return new non_streaming_asr.OfflineStream(
  19. addon.createSpokenLanguageIdentificationOfflineStream(this.handle));
  20. }
  21. /**
  22. * Return a 2-letter language code, e.g. 'en', 'de', 'fr', 'es', 'zh'
  23. * @param {OfflineStream} stream
  24. * @returns {string}
  25. */
  26. compute(stream) {
  27. return addon.spokenLanguageIdentificationCompute(
  28. this.handle, stream.handle);
  29. }
  30. }
  31. module.exports = {
  32. SpokenLanguageIdentification,
  33. }