繁体   English   中英

使用Watson Unity SDK文本语音转换示例时的错误

[英]Errors when using Watson Unity SDK Text to Speech Example

我试图使用Watson Unity SDK随附的示例脚本“ ExampleTextToSpeech”。 但是,Watson Text to Speech示例在尝试合成时会引发错误。 我的服务IAM密钥似乎正确。 我没有指定AIM URL或服务URL。 我认为默认值应该是正确的,因为我在北美地区,并且对Watson Assistant和语音转文本都有效。 问题似乎出在Synthesize调用上。 我在下面列出了错误。

抱歉,我第一次没有发布实际代码。 我以为我不需要,因为它与SDK演示中的代码相同。 请在下面找到代码。 我删除了一些无关的代码位,例如从代码中定制单词。 错误可以在代码块的末尾找到。

using UnityEngine;
using IBM.Watson.DeveloperCloud.Services.TextToSpeech.v1;
using IBM.Watson.DeveloperCloud.Logging;
using IBM.Watson.DeveloperCloud.Utilities;
using System.Collections;
using System.Collections.Generic;
using IBM.Watson.DeveloperCloud.Connection;

public class TTS : MonoBehaviour
{
    //Iam Apikey: v0qlUa8hojlVW8rKBh48fO0JtQYTO9vfNkGMG6wpptbs
    #region PLEASE SET THESE VARIABLES IN THE INSPECTOR
    [Space(10)]
    [Tooltip("The service URL (optional). This defaults to \"https://stream.watsonplatform.net/text-to-speech/api\"")]
    [SerializeField]
    private string _serviceUrl;
    [Header("CF Authentication")]
    [Tooltip("The authentication username.")]
    [SerializeField]
    private string _username;
    [Tooltip("The authentication password.")]
    [SerializeField]
    private string _password;
    [Header("IAM Authentication")]
    [Tooltip("The IAM apikey.")]
    [SerializeField]
    private string _iamApikey;
    [Tooltip("The IAM url used to authenticate the apikey (optional). This defaults to \"https://iam.bluemix.net/identity/token\".")]
    [SerializeField]
    private string _iamUrl;

    #endregion

    TextToSpeech _service;
    string _testString = "<speak version=\"1.0\"><say-as interpret-as=\"letters\">I'm sorry</say-as>. <prosody pitch=\"150Hz\">This is Text to Speech!</prosody><express-as type=\"GoodNews\">I'm sorry. This is Text to Speech!</express-as></speak>";

    string _createdCustomizationId;
    CustomVoiceUpdate _customVoiceUpdate;
    string _customizationName = "unity-example-customization";
    string _customizationLanguage = "en-US";
    string _customizationDescription = "A text to speech voice customization created within Unity.";
    string _testWord = "Watson";

    private bool _synthesizeTested = false;
    private bool _getVoicesTested = false;
    private bool _getVoiceTested = false;
    private bool _getPronuciationTested = false;
    private bool _getCustomizationsTested = false;
    private bool _createCustomizationTested = false;
    private bool _deleteCustomizationTested = false;
    private bool _getCustomizationTested = false;
    private bool _updateCustomizationTested = false;
    private bool _getCustomizationWordsTested = false;
    private bool _addCustomizationWordsTested = false;
    private bool _deleteCustomizationWordTested = false;
    private bool _getCustomizationWordTested = false;

    void Start()
    {
        LogSystem.InstallDefaultReactors();
        Runnable.Run(CreateService());
    }

    private IEnumerator CreateService()
    {
        //  Create credential and instantiate service
        Credentials credentials = null;
        if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_password))
        {
            //  Authenticate using username and password
            credentials = new Credentials(_username, _password, _serviceUrl);
        }
        else if (!string.IsNullOrEmpty(_iamApikey))
        {
            //  Authenticate using iamApikey
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey = _iamApikey,
                IamUrl = _iamUrl
            };

            credentials = new Credentials(tokenOptions, _serviceUrl);

            //  Wait for tokendata
            while (!credentials.HasIamTokenData())
                yield return null;
        }
        else
        {
            throw new WatsonException("Please provide either username and password or IAM apikey to authenticate the service.");
        }

        _service = new TextToSpeech(credentials);

        Runnable.Run(Examples());
    }

    private IEnumerator Examples()
    {
        //  Synthesize
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting synthesize.");
        _service.Voice = VoiceType.en_US_Allison;
        _service.ToSpeech(HandleToSpeechCallback, OnFail, _testString, true);
        while (!_synthesizeTested)
            yield return null;

        //  Get Voices
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting to get voices.");
        _service.GetVoices(OnGetVoices, OnFail);
        while (!_getVoicesTested)
            yield return null;

        //  Get Voice
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting to get voice {0}.", VoiceType.en_US_Allison);
        _service.GetVoice(OnGetVoice, OnFail, VoiceType.en_US_Allison);
        while (!_getVoiceTested)
            yield return null;

        Log.Debug("ExampleTextToSpeech.Examples()", "Text to Speech examples complete.");
    }

    void HandleToSpeechCallback(AudioClip clip, Dictionary<string, object> customData = null)
    {
        PlayClip(clip);
    }

    private void PlayClip(AudioClip clip)
    {
        if (Application.isPlaying && clip != null)
        {
            GameObject audioObject = new GameObject("AudioObject");
            AudioSource source = audioObject.AddComponent<AudioSource>();
            source.spatialBlend = 0.0f;
            source.loop = false;
            source.clip = clip;
            source.Play();

            Destroy(audioObject, clip.length);

            _synthesizeTested = true;
        }
    }

    private void OnGetVoices(Voices voices, Dictionary<string, object> customData = null)
    {
        Log.Debug("ExampleTextToSpeech.OnGetVoices()", "Text to Speech - Get voices response: {0}", customData["json"].ToString());
        _getVoicesTested = true;
    }

    private void OnGetVoice(Voice voice, Dictionary<string, object> customData = null)
    {
        Log.Debug("ExampleTextToSpeech.OnGetVoice()", "Text to Speech - Get voice  response: {0}", customData["json"].ToString());
        _getVoiceTested = true;
    }

    private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
    {
        Log.Error("ExampleTextToSpeech.OnFail()", "Error received: {0}", error.ToString());
    }
}




    [12/11/2018 16:57:45][RESTConnector.ProcessRequestQueue()][ERROR] URL: /v1/synthesize?accept=audio%2fwav&voice=en-US_AllisonVoice&text=%3cspeak+version%3d%221.0%22%3e%3csay-as+interpret-as%3d%22letters%22%3eI%27m+sorry%3c%2fsay-as%3e.+%3cprosody+pitch%3d%22150Hz%22%3eThis+is+Text+to+Speech%21%3c%2fprosody%3e%3cexpress-as+type%3d%22GoodNews%22%3eI%27m+sorry.+This+is+Text+to+Speech%21%3c%2fexpress-as%3e%3c%2fspeak%3e, ErrorCode: 0, Error: Cannot connect to destination host, Response: 
    UnityEngine.Debug:LogError(Object)
    IBM.Watson.DeveloperCloud.Debug.DebugReactor:ProcessLog(LogRecord) (at Assets/Watson/Scripts/Debug/DebugReactor.cs:60)
    IBM.Watson.DeveloperCloud.Logging.LogSystem:ProcessLog(LogRecord) (at Assets/Watson/Scripts/Logging/Logger.cs:206)
    IBM.Watson.DeveloperCloud.Logging.Log:Error(String, String, Object[]) (at Assets/Watson/Scripts/Logging/Logger.cs:279)
    IBM.Watson.DeveloperCloud.Connection.<ProcessRequestQueue>c__Iterator0:MoveNext() (at Assets/Watson/Scripts/Connection/RESTConnector.cs:607)
    IBM.Watson.DeveloperCloud.Utilities.Routine:MoveNext() (at Assets/Watson/Scripts/Utilities/Runnable.cs:131)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)



    [12/11/2018 16:57:45][ExampleTextToSpeech.OnFail()][ERROR] Error received: URL: /v1/synthesize?accept=audio%2fwav&voice=en-US_AllisonVoice&text=%3cspeak+version%3d%221.0%22%3e%3csay-as+interpret-as%3d%22letters%22%3eI%27m+sorry%3c%2fsay-as%3e.+%3cprosody+pitch%3d%22150Hz%22%3eThis+is+Text+to+Speech%21%3c%2fprosody%3e%3cexpress-as+type%3d%22GoodNews%22%3eI%27m+sorry.+This+is+Text+to+Speech%21%3c%2fexpress-as%3e%3c%2fspeak%3e, ErrorCode: 0, Error: Cannot connect to destination host, Response: 
    UnityEngine.Debug:LogError(Object)
    IBM.Watson.DeveloperCloud.Debug.DebugReactor:ProcessLog(LogRecord) (at Assets/Watson/Scripts/Debug/DebugReactor.cs:60)
    IBM.Watson.DeveloperCloud.Logging.LogSystem:ProcessLog(LogRecord) (at Assets/Watson/Scripts/Logging/Logger.cs:206)
    IBM.Watson.DeveloperCloud.Logging.Log:Error(String, String, Object[]) (at Assets/Watson/Scripts/Logging/Logger.cs:279)
    TTS:OnFail(Error, Dictionary`2) (at Assets/Scripts/TTS.cs:158)
    IBM.Watson.DeveloperCloud.Services.TextToSpeech.v1.TextToSpeech:ToSpeechResponse(Request, Response) (at Assets/Watson/Scripts/Services/TextToSpeech/v1/TextToSpeech.cs:492)
    IBM.Watson.DeveloperCloud.Connection.<ProcessRequestQueue>c__Iterator0:MoveNext() (at Assets/Watson/Scripts/Connection/RESTConnector.cs:647)
    IBM.Watson.DeveloperCloud.Utilities.Routine:MoveNext() (at Assets/Watson/Scripts/Utilities/Runnable.cs:131)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

您应该为您所在地区的“文字转语音”服务明确使用服务URL。 这是美国南部的URL

https://stream.watsonplatform.net/text-to-speech/api

SDK存在一个问题,其中未使用默认服务URL。 合并此拉取请求后,该问题将得到解决。

https://github.com/watson-developer-cloud/unity-sdk/pull/486

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM