'Capacitor text-to-speech API not working on android

I am getting this error whenever I try to execute the TextToSpeech.speak() function from @capacitor-community/[email protected]:

Uncaught (in promise) Error: Not supported on this device.
    at n.value (29.a169ec33.chunk.js:formatted:3022)
    at n.<anonymous> (29.a169ec33.chunk.js:formatted:2842)
    at c (26.902cd79a.chunk.js:2)
    at Generator._invoke (26.902cd79a.chunk.js:2)
    at Generator.next (26.902cd79a.chunk.js:2)
    at 29.a169ec33.chunk.js:formatted:2816
    at new Promise (<anonymous>)
    at l (29.a169ec33.chunk.js:formatted:2793)
    at n.value (29.a169ec33.chunk.js:formatted:2836)
    at 29.a169ec33.chunk.js:formatted:4997

Here is my code below:

import { TextToSpeech } from '@capacitor-community/text-to-speech';

const androidSpeak = async () => {
    await TextToSpeech.speak({
      text: 'This is a sample text.',
      locale: 'en_US',
      pitchRate: 1.0,
      speechRate: 1.0,
      volume: 1.0,
      category: 'ambient',
    });
  };

Whenever I trigger the function it gives me the error above. Anyone experienced it before?

Modules: @capacitor/android: ^2.4.2 @capacitor-community/text-to-speech: ^0.2.3 https://github.com/capacitor-community/text-to-speech



Solution 1:[1]

Change the language from 'en_US' to 'en' and it will work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 teoole