Skip to content

"TypeError: Right-hand side of 'instanceof' is not an object" when I tried to add the service for TNSTextToSpeech. #26

Description

@hims1911

I've created a service file for TNSTextToSpeech as speak.service.ts :

import { Injectable }             from '@angular/core';
import { TNSTextToSpeech, SpeakOptions } from '@nativescript-community/texttospeech';

@Injectable({
  providedIn: 'root'
})
export class SpeakerService {


  TTS : TNSTextToSpeech;
  constructor() {
      this.TTS = new TNSTextToSpeech();
  }

  play(text : string) {
    let speakOptions: SpeakOptions = {
        text: text, /// *** required ***
        speakRate: 1.0, // optional - default is 1.0
        pitch: 1.0, // optional - default is 1.0
        volume: 1.0, // optional - default is 1.0
        language: 'en',  // optional - default is system language,
        finishedCallback: () => {
          console.log("We have finish to read text");
        } // optional
    }
    this.TTS.speak(speakOptions);
  }

  destroy(){
      this.TTS.destroy();
  }
}

Then I've injected this service into the home component constructor and it giving us the error :

System.err: An uncaught Exception occurred on "main" thread.
System.err: Calling js method onCreateView failed
System.err: TypeError: Right-hand side of 'instanceof' is not an object
System.err:
System.err: StackTrace:
System.err: (file: node_modules\@nativescript\core\ui\layouts\flexbox-layout\flexbox-layout.android.js:14:0)
System.err:     at applyAllNativeSetters(file: node_modules\@nativescript\core\ui\core\properties\properties.js:1065:0)
System.err:     at initNativeView(file: node_modules\@nativescript\core\ui\core\properties\properties.js:992:0)
System.err:     at push.../node_modules/@nativescript/core/ui/core/view-base/view-base.js.ViewBase.onResumeNativeUpdates(file: node_modules\@nativescript\core\ui\core\view-base\view-base.js:647:0)```

It doesn't seem to be working when I tried to inject in the constructor. 

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions