question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ASR for multiple languages in angular demo

See original GitHub issue

hello

Thank you for sharing your knowledge

I want to use multiple languages in the Angular program demo.

For this purpose, I changed the following code in app.component.ts :

import { Component } from '@angular/core';
import { ElementRef, ViewChild} from '@angular/core'
import { DictateService } from "./dictate-service";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  providers: [DictateService]
})

export class AppComponent {

  @ViewChild('results') private results: ElementRef;

  buttonText = 'شروع ضبط';
  buttonText_russian = 'شروع ضبط';
  textDataBase = '';
  textData = '';

  persian_server = "ws://localhost:2700";

  russian_server = "ws://localhost:2701";

  constructor(private dictateService: DictateService) {
    
  }

  switchSpeechRecognition() {
    if ( !this.dictateService.isInitialized() || this.persian_server === null ) {
      this.persian_server = "ws://localhost:2700";
      this.russian_server = null ;

      this.dictateService.cancel();

      this.dictateService.init({
        server: this.persian_server,
        onResults: (hyp) => {
          console.log(hyp);
  
          this.textDataBase = this.textDataBase + hyp + '\n';
          this.textData = this.textDataBase;
          this.results.nativeElement.scrollTop = this.results.nativeElement.scrollHeight;
        },
        onPartialResults: (hyp) => {
          console.log(hyp);
  
          this.textData = this.textDataBase + hyp;
        },
        onError: (code, data) => {
          console.log(code, data);
        },
        onEvent: (code, data) => {
          console.log(code, data);
        }
      });

      this.buttonText_russian = 'شروع ضبط';
      document.getElementById("listening_gif").style.display = "none";

      this.buttonText = 'پایان ضبط';
      document.getElementById("listening_gif").style.display = "inline";
    } else if (this.dictateService.isRunning()) {
      this.dictateService.resume();
      this.buttonText = 'پایان ضبط';
      document.getElementById("listening_gif").style.display = "inline";
    } else {
      this.dictateService.pause();
      this.buttonText = 'شروع ضبط';
      document.getElementById("listening_gif").style.display = "none";
    }
  }

  cleararea() {
    var cl = document.getElementById("textarea") ;
    console.log(cl);
    cl.value = "";
    this.textDataBase = '';
  }

  switchSpeechRecognition_russian() {
    if ( !this.dictateService.isInitialized() || this.russian_server === null ) {
      this.persian_server = null;
      this.russian_server = "ws://localhost:2701" ;

      this.dictateService.cancel();

      this.buttonText = 'شروع ضبط';
      document.getElementById("listening_gif").style.display = "none";

      this.dictateService.init({
        server: this.russian_server,
        onResults: (hyp) => {
          console.log(hyp);
  
          this.textDataBase = this.textDataBase + hyp + '\n';
          this.textData = this.textDataBase;
          this.results.nativeElement.scrollTop = this.results.nativeElement.scrollHeight;
        },
        onPartialResults: (hyp) => {
          console.log(hyp);
  
          this.textData = this.textDataBase + hyp;
        },
        onError: (code, data) => {
          console.log(code, data);
        },
        onEvent: (code, data) => {
          console.log(code, data);
        }
      });

      this.buttonText_russian = 'پایان ضبط';
      document.getElementById("listening_gif").style.display = "inline";
    } else if (this.dictateService.isRunning()) {
      this.dictateService.resume();
      this.buttonText_russian = 'پایان ضبط';
      document.getElementById("listening_gif").style.display = "inline";
    } else {
      this.dictateService.pause();
      this.buttonText_russian = 'شروع ضبط';
      document.getElementById("listening_gif").style.display = "none";
    }
  }

}

The correct results are displayed for the first time, but when I select another language, the results are no longer correct.

I think the error is in following code , but I do not know how to correct it

node.onaudioprocess = (e) => {
      if (this.paused) return;

      // console.log("00000000000000000000000000000000000000000000000");
      // console.log(e.inputBuffer.getChannelData(0));
      // console.log("00000000000000000000000000000000000000000000000");

      this.worker.postMessage({
        command: 'record',
        buffer: [
          e.inputBuffer.getChannelData(0)
        ]
      });
    };

please help.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
nshmyrevcommented, Sep 28, 2021

No the problem is not in the code,

Again, the problem is in your code, our code doesn’t have this feature at all

it sends 1024 array in 500 sec interval which results in a buffer size 44k ( a record request is sent every ~10-12 ms)

Most likely you subscribe to audio stream twice (like you call startUserMedia several times) so you get each audio chunk many times. You shouldn’t do that when you switch languages.

1reaction
NadaAzzzamcommented, Sep 28, 2021

It works very good when i call startUserMedia once… thank you very much

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple Language Support in Angular Application using i18n
In this article, we will discuss about “how our angular application can support multiple languages”. But wait do our application really need ...
Read more >
Speech-to-Text supported languages - Google Cloud
Name BCP‑47 Model Boost Profanity filter Afrikaans (South Africa) af‑ZA Command and search ✓ ✓ Afrikaans (South Africa) af‑ZA Default ✓ ✓ Albanian (Albania) sq‑AL Command...
Read more >
Speech to Text – Audio to Text Translation | Microsoft Azure
Convert spoken audio to text within your apps for more accessible converted audio to ... transcribe audio to text in more than 100...
Read more >
Porcupine Wake Word | Angular - Picovoice Docs
Picovoice Account and AccessKey; Node.js 14+; Angular 13+; npm ... In order to use Porcupine with other languages, you need to use the...
Read more >
Angular: creating a multilanguage application - YouTube
Angular creating a multilanguage application with json files for every corresponding language. In this tutorial I will explain to you how to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found