First sound playing is long to start
GrEg00z opened this issue · comments
After every startup of my app, I have to wait maybe 10 secondes before the first sound start to play, when using :
this.TTS.speak(speakOptions);
After the first sound finished, all others calls to this.TTS.speak are directly played.
I've tried to re-install the app but nothing changes
Yes it makes sense :)
I'm playing the sound after user interaction, on a tap event action.
I'm using nativescript with angular, and I created an 'angular' service in my app that instanciate TNSTextToSpeech , which is initialized after app start (declared as provider in my app.module file).
So I use only one instance of TNSTextToSpeech in my app, which is instanciate long time before I call this.TTS.speak (method play() in my service).
Systematically, the time to wait is about 10-12 seconds
Here the service I created :
import { Injectable } from '@angular/core';
import { TNSTextToSpeech, SpeakOptions } from 'nativescript-texttospeech';
@Injectable()
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: "fr-FR", // optional - default is system language,
finishedCallback: () => {
console.log("We have finish to read text");
} // optional
}
this.TTS.speak(speakOptions);
}
}
Can you confirm, maybe with some console.logs() in the constructor the timing before/after the this.TTS = new...
and see how long it's taking and when it's being initialized? I'd also try logging out this.TTS
inside the play
method and see if it's the same instance the constructor creates. They should log the same value if so.
Yes it's well instanciate during app start, it takes no time.
Also there is no callback or others ways (like observale or promise) to detect that the synthesizer is ready to be used, asynchronously.
I've just added this to detect that TNSTextToSpeech is ready :
constructor() {
console.log("init SpeakerService")
this.TTS = new TNSTextToSpeech();
console.log("end init SpeakerService", JSON.stringify(this.TTS))
}
I've checked this.TTS inside play method, it also have the same instance as constructor
I can also confirm that when I add this inside finishedCallback function (in play method) :
this.TTS.destroy();
this.TTS = new TNSTextToSpeech();
Then every next call to play method take also 10-12s to play.
Information : I use android 7.1.1 with Nexus 5X
Yeah it's not also what I want destroy the instance
It was just for yours informations and help for debug.
But anyway it's still a problem to be used in my app.
I will try to give you more informations about this
I confirm the long delay of instanciation as it happened with GrEg00z ( arround 10-12 sec), and by the way, only when I use the english language en-USA, it is much faster in instanciation
Yes the same for me, with english language it's very fast on first playing
On android it's a second or two to init for the device I have. I don't have any iOS devices to test the result there. Sorry. I don't have time to dig in and see what can be done to improve this. If someone wants to help I can answer any questions they might have. I would first start with viewing official documentation on the native speech synthesizers, finding an example from apple and google on using it and then lets make sure we implement it the same way. Then we can look at adding a NS background thread (worker) to the init and see if that's something we can implement with this plugin and run the speech synth on a worker thread 👍
https://github.com/bradmartin/nativescript-texttospeech#tip - this should help reduce initial time on the first speak
call.