每当我尝试从
TextToSpeech.speak()
执行 @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
下面是我的代码:
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',
});
};
每当我触发该功能时,它都会出现上述错误。有人经历过吗?
模块:
@capacitor/android: ^2.4.2
@capacitor-community/text-to-speech: ^0.2.3
https://github.com/capacitor-community/text-to-speech
如果您在设备上使用 Android 10+,请将这些行添加到您的 androidManifest.xml 中尝试,这可以解决我的问题。从 Android 11 开始需要此功能
像这样, 在此输入图片描述
将语言从“en_US”更改为“en”即可。