Capacitor 文本转语音 API 在 Android 上不起作用

问题描述 投票:0回答:2

每当我尝试从

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 text-to-speech capacitor capacitor-plugin
2个回答
0
投票
  1. 如果您在设备上使用 Android 10+,请将这些行添加到您的 androidManifest.xml 中尝试,这可以解决我的问题。从 Android 11 开始需要此功能

像这样, 在此输入图片描述

  1. 确保您的设备有可用的 TTS,某些设备可能未安装 TTS 引擎。您可以下载 TTS 引擎 apk 安装程序来修复此问题。

-1
投票

将语言从“en_US”更改为“en”即可。

© www.soinside.com 2019 - 2024. All rights reserved.