capacitor-community / text-to-speech

⚡️ Capacitor plugin for synthesizing speech from text.
MIT License
93 stars 24 forks source link

Speech not working (returning undefined) #71

Closed infinitronic closed 2 years ago

infinitronic commented 2 years ago

Hello I've been trying to get capacitor tts to work on Android for around a week but thus far have been unable to.

It keeps returning this error in logcat:

Line xxxx - Msg: Uncaught (in promise) ReferenceError: speech_function is not defined

speech_function literally follows verbatim the instructions in the docs i.e.:

//capacitor plugin for speech import { TextToSpeech } from '@capacitor-community/text-to-speech'; let speech_function = async (m_word) => { await TextToSpeech.stop();

await TextToSpeech.speak({ text: m_word, lang: 'en_US', rate: 1.3, pitch: 0.9, volume: 1.0, category: 'ambient', }); };

The gradle files for the plugin have been included after npx cap sync and then sycning the gradle files with the project, I'm wondering if I missed anything?

robingenz commented 2 years ago

Hi @infinitronic, thank you for your request. Please fill out the issue template correctly so I get all the information I need.

infinitronic commented 2 years ago

Thank you so much @roibingenz for your swift response.

Here's the full load:

Plugin version:

"@capacitor-community/text-to-speech": "^1.1.1"

Platform(s):

Android

Current behavior:

I've been trying to get capacitor tts to work on Android for around a week but thus far have been unable to.

It keeps returning this error in logcat:

Line xxxx - Msg: Uncaught (in promise) ReferenceError: speech_function is not defined

speech_function literally follows verbatim the instructions in the docs i.e.:

//capacitor plugin for speech
import { TextToSpeech } from '@capacitor-community/text-to-speech';
let speech_function = async (m_word) => {
await TextToSpeech.stop();

await TextToSpeech.speak({
text: m_word,
lang: 'en_US',
rate: 1.3,
pitch: 0.9,
volume: 1.0,
category: 'ambient',
});
};

The gradle files for the plugin have been included after npx cap sync and then sycning the gradle files with the project, I'm wondering if I missed anything? I had to refactor the speech_function( ) from its Javascript SpeechSynthesis equivalent: in the JS function, I did calls to getVoices... but I did not include such code in the tts plugin:L I'm wondering if that's an issue?

Expected behavior:

The speech function should work i.e. when speech_function( ) defined above is called, it should produce speech via translating the text provided to speech.

Steps to reproduce:

Use this code to produce speech from text (m_word):

//capacitor plugin for speech
import { TextToSpeech } from '@capacitor-community/text-to-speech';
let speech_function = async (m_word) => {
await TextToSpeech.stop();

await TextToSpeech.speak({
text: m_word,
lang: 'en_US',
rate: 1.3,
pitch: 0.9,
volume: 1.0,
category: 'ambient',
});
};

If this code works well on your end, then the problem may be comimng from some other aspect of the app

Related code:

Alreadty inserted in relevant segments for integrability and flow

Other information:

Capacitor doctor:

insert the output from `npx cap doctor` here

npx cap doctor Capacitor Doctor

Latest Dependencies:

@capacitor/cli: 3.3.2 @capacitor/core: 3.3.2 @capacitor/android: 3.3.2 @capacitor/ios: 3.3.2

Installed Dependencies:

@capacitor/ios: not installed @capacitor/cli: 3.3.1 @capacitor/android: 3.3.1 @capacitor/core: 3.3.1

[success] Android looking great! 👌

THANK YOU SO MUCH FOR YOUR SWIFT ATTENTION ROBINGENZ!

robingenz commented 2 years ago

I'm not sure i understand the problem correctly.

Line xxxx - Msg: Uncaught (in promise) ReferenceError: speech_function is not defined

As far as I can see you define the function speech_function. Thus, you should check why your function is not defined. This doesn't look like a problem with the plugin.

Here you can find a working example: robingenz/capacitor-plugin-demo Best have a look at this.

infinitronic commented 2 years ago

Hello @robingenz. Thanks for your super swift responses. I'm having issues getting the demo app up and running here. I've tried with multiple virtual devices and the result is similar. Here's the error message I get:

[ERROR] An error occurred while running subprocess capacitor.

    capacitor.cmd run android --target Nexus_5_API_28 exited with exit code
    1.

    Re-running this command with the --verbose flag may provide more
    information.

ionic:utils-process onBeforeExit handler: 'process.exit' received +0ms ionic:utils-process onBeforeExit handler: running 2 functions +1ms ionic:utils-process error while killing process tree for 10776: Error: Command failed: taskkill /pid 10776 /T /F ionic:utils-process ERROR: The process "10776" not found. ionic:utils-process ionic:utils-process at ChildProcess.exithandler (node:child_process:397:12 ) ionic:utils-process at ChildProcess.emit (node:events:390:28) ionic:utils-process at maybeClose (node:internal/child_process:1064:16) ionic:utils-process at Process.ChildProcess._handle.onexit (node:internal/ child_process:301:5) { ionic:utils-process killed: false, ionic:utils-process code: 128, ionic:utils-process signal: null, ionic:utils-process cmd: 'taskkill /pid 10776 /T /F' ionic:utils-process } +6s ionic:utils-process onBeforeExit handler: error from function: Error: Command failed: taskkill /pid 10776 /T /F ionic:utils-process ERROR: The process "10776" not found. ionic:utils-process ionic:utils-process at ChildProcess.exithandler (node:child_process:397:12 ) ionic:utils-process at ChildProcess.emit (node:events:390:28) ionic:utils-process at maybeClose (node:internal/child_process:1064:16) ionic:utils-process at Process.ChildProcess._handle.onexit (node:internal/ child_process:301:5) { ionic:utils-process killed: false, ionic:utils-process code: 128, ionic:utils-process signal: null, ionic:utils-process cmd: 'taskkill /pid 10776 /T /F' ionic:utils-process } +5ms ionic:utils-process error while killing process tree for 20720: Error: Command failed: taskkill /pid 20720 /T /F ionic:utils-process ERROR: The process "20720" not found. ionic:utils-process ionic:utils-process at ChildProcess.exithandler (node:child_process:397:12 ) ionic:utils-process at ChildProcess.emit (node:events:390:28) ionic:utils-process at maybeClose (node:internal/child_process:1064:16) ionic:utils-process at Process.ChildProcess._handle.onexit (node:internal/ child_process:301:5) { ionic:utils-process killed: false, ionic:utils-process code: 128, ionic:utils-process signal: null, ionic:utils-process cmd: 'taskkill /pid 20720 /T /F' ionic:utils-process } +3ms ionic:utils-process onBeforeExit handler: error from function: Error: Command failed: taskkill /pid 20720 /T /F ionic:utils-process ERROR: The process "20720" not found. ionic:utils-process ionic:utils-process at ChildProcess.exithandler (node:child_process:397:12 ) ionic:utils-process at ChildProcess.emit (node:events:390:28) ionic:utils-process at maybeClose (node:internal/child_process:1064:16) ionic:utils-process at Process.ChildProcess._handle.onexit (node:internal/ child_process:301:5) { ionic:utils-process killed: false, ionic:utils-process code: 128, ionic:utils-process signal: null, ionic:utils-process cmd: 'taskkill /pid 20720 /T /F' ionic:utils-process } +3ms ionic:utils-process processExit: exiting (exit code: 1) +2ms

Viz my project proper: I'm also seeing a lot of other error messages in logcat: e.g. 19.043 7421-7421/com.potara.bazaaar E/Capacitor/Console: File: http://localhost/movement.js - Line 279 - Msg: Uncaught (in promise) NotSupportedError: The element has no supported sources.

And that, for an audio file that is certainly present in the project - yet it is being reported to not be there. And a lot of other vanilla Javascript functionalities do not also work - which work perfectly on the web app and on the electron app, which are all spin-offs of the same base Javascript code.

This is my first time using Capacitor, and I was hoping for a seamless translation of the app from it's vanila Javascript base to Android and then iOS: like: run the commands, and APPS READY!