首页 > 解决方案 > 如何在 Cocos creator Java 脚本中使用 text to Speech 功能 - Android/IOS APP

问题描述

我正在开发一个 cocos creator 游戏,它同时构建了 android 和 IOS 版本。我需要在该应用程序中添加“文本到语音”功能。但是我尝试了很多来找到文本到语音的 API,但它们都不能与 Android/IOS 应用程序一起使用。

以下解决方案也仅适用于 Web 浏览器。

在 Javascript 中使用 Google 文字转语音

所以我决定使用 Google Cloud - 文本到语音 API,但经过大量尝试,我决定向大家询问......

根据我对 Google Cloud 的理解,我们提供了以下详细信息。

请求网址:https ://texttospeech.googleapis.com/v1beta1/text:synthesize

请求正文:

{
  "audioConfig": {
    "audioEncoding": "LINEAR16",
    "pitch": 0,
    "speakingRate": 1
  },
  "input": {
    "text": "Hello world"
  },
  "voice": {
    "languageCode": "en-US",
    "name": "en-US-Wavenet-D"
  }
}

我想我必须使用上述信息编写 HTTP Post 请求才能获得翻译。我写了示例服务器请求,但没有给出好的结果。请看下面..

sendServerReq : function(){
    var restChannel = cc.loader.getXMLHttpRequest();
    restChannel.open("POST", 'https://texttospeech.googleapis.com/v1beta1/text:synthesize', true);
    restChannel.setRequestHeader("Content-Type", "application/json");

    var jsonObj = {
        "audioConfig": {
          "audioEncoding": "LINEAR16",
          "pitch": 0,
          "speakingRate": 1
        },
        "input": {
          "text": "おはようございます"
        },
        "voice": {
          "languageCode": "ja-JP",
          "name": "ja-JP-Standard-B"
        }
    };


    var response = restChannel.send(jsonObj);
},

你能告诉我如何使用谷歌云来实现“文本到语音”功能,或者是否有任何免费的 API 可以在 COCCOS Creator Android/IOS 应用程序中获取文本到语音功能。

非常感谢

我需要的是在我的游戏应用程序中添加文本到语音功能

sendServerReq : function(){
    var restChannel = cc.loader.getXMLHttpRequest();
    restChannel.open("POST", 'https://texttospeech.googleapis.com/v1beta1/text:synthesize', true);
    restChannel.setRequestHeader("Content-Type", "application/json");

    var jsonObj = {
        "audioConfig": {
          "audioEncoding": "LINEAR16",
          "pitch": 0,
          "speakingRate": 1
        },
        "input": {
          "text": "おはようございます"
        },
        "voice": {
          "languageCode": "ja-JP",
          "name": "ja-JP-Standard-B"
        }
    };


    var response = restChannel.send(jsonObj);
},
  1. 那是一个错误。

/v1beta1/text:synthesize在此服务器上找不到请求的 URL

标签: javascripttext-to-speechcocos2d-jsgoogle-text-to-speechcocoscreator

解决方案


推荐阅读