Интеграция IBM Watson TTS в проект Unity VRC#

Место общения программистов C#
Ответить
Anonymous
 Интеграция IBM Watson TTS в проект Unity VR

Сообщение Anonymous »

Для начала я просто хочу создать небольшую сцену с полем ввода, куда вы можете ввести текст, который затем будет выведен после того, как вы нажмете Enter. Я спроектировал все согласно тестовому примеру из Watson Unity SDK https://github.com/watson-developer-cloud/unity-sdk.
Я построил эту сцену:
Изображение

И написал этот код:

Код: Выделить всё

using IBM.Watson.TextToSpeech.V1;
using IBM.Watson.TextToSpeech.V1.Model;
using IBM.Cloud.SDK.Utilities;
using IBM.Cloud.SDK.Authentication;
using IBM.Cloud.SDK.Authentication.Iam;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using IBM.Cloud.SDK;

namespace IBM.Watson.Examples
{
public class ExampleTextToSpeechV1 : MonoBehaviour
{
#region PLEASE SET THESE VARIABLES IN THE INSPECTOR
[Space(10)]
[Tooltip("The IAM apikey.")]
[SerializeField]
private string iamApikey = "APIKEY";
[Tooltip("The service URL (optional).  This defaults to \"https://api.us-south.text-to-speech.watson.cloud.ibm.com\"")]
[SerializeField]
private string serviceUrl = "https://api.eu-de.text-to-speech.watson.cloud.ibm.com/instances/SERVICEINSTANCE";
private TextToSpeechService service;
private string allisionVoice = "en-US_AllisonV3Voice";
private string synthesizeText = "Hello, my Name is Niclas.";
private string placeholderText = "Please type text here and press enter.";
private string waitingText = "Watson Text to Speech service is synthesizing the audio!";
private string synthesizeMimeType = "audio/wav";
public InputField textInput;
private bool _textEntered = false;
private AudioClip _recording = null;
private byte[] audioStream = null;
#endregion

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

void Update()
{
if (Input.GetKeyDown(KeyCode.Return))
{
Runnable.Run(ExampleSynthesize(textInput.text));
}
}

private IEnumerator CreateService()
{
if (string.IsNullOrEmpty(iamApikey))
{
throw new IBMException("Please add IAM ApiKey to the Iam Apikey field in the inspector.");
}

IamAuthenticator authenticator = new IamAuthenticator(apikey: iamApikey);

while (!authenticator.CanAuthenticate())
{
yield return null;
}

service = new TextToSpeechService(authenticator);
if (!string.IsNullOrEmpty(serviceUrl))
{
service.SetServiceUrl(serviceUrl);
}
}

#region Synthesize Example
private IEnumerator ExampleSynthesize(string text)
{
if (string.IsNullOrEmpty(text))
{
text = synthesizeText;
Log.Debug("ExampleTextToSpeechV1", "Using default text, please enter your own text in dialog box!");

}
byte[] synthesizeResponse = null;
AudioClip clip = null;
service.Synthesize(
callback: (DetailedResponse response, IBMError error) =>
{
synthesizeResponse = response.Result;
Log.Debug("ExampleTextToSpeechV1", "Synthesize done!");
clip = WaveFile.ParseWAV("myClip", synthesizeResponse);
PlayClip(clip);
},
text: text,
voice: allisionVoice,
accept: synthesizeMimeType
);

while (synthesizeResponse == null)
yield return null;

yield return new WaitForSeconds(clip.length);
}
#endregion

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

GameObject.Destroy(audioObject, clip.length);
}
}
#endregion
}
}

Я понятия не имею, в чем заключается моя проблема и как устранить ошибки, показанные на снимке экрана выше.


Подробнее здесь: https://stackoverflow.com/questions/782 ... vr-project
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»