How to run AWS text-to-speech service (Amazon Polly) with MetaQuest Pro (Oculus Quest Pro)

157 Views Asked by At

I would like to run AmazonPolly in an application built for MetaQuestPro in Unity. Environment Unity2021.3.25f1 MetaQuestPro

When debugging with QuestLink, a Quest feature, connected to a PC, it plays, but when built for QuestPro, it does not play on QuestPro. The following code is attached to the object and sets the text to be read on the inspector.

Is there a way to do this in Quest?

using System.IO;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using Amazon.Polly;
using Amazon.Polly.Model;

public class PollyTTS : MonoBehaviour
{
    //public VoiceType voiceType;
    public string text;
    private AmazonPollyClient client;
    private AudioSource audioSource;
    private List<FieldInfo> voiceList = new List<FieldInfo>();

    private string fileName = "voice.ogg";

    void Start()
    {
        audioSource = gameObject.AddComponent<AudioSource>();

        string voiceNames = "";
        var list = typeof(VoiceId).GetFields();
        foreach (FieldInfo prop in list)
        {
            voiceNames += prop.Name + ",";
            voiceList.Add(prop);
        }
        StartCoroutine(Speak());
    }
    private void Update()
    {
        // if (Input.GetKey(KeyCode.Space))
        // {
        //     StartCoroutine(Speak());
        // }
    }

    private IEnumerator Speak()
    {
        // AWSのIAMからアクセスキーIDとシークレットアクセスキーを取得して書き換える
        client = new AmazonPollyClient("awsAccessKeyId", "awsSecretAccessKey", region);
        SynthesizeSpeechRequest sreq = new SynthesizeSpeechRequest();
        sreq.Text = text;
        sreq.OutputFormat = OutputFormat.Ogg_vorbis;
        // sreq.VoiceId = voiceList[(int)voiceType].GetValue(null) as VoiceId;
        // ボイスIDを日本語(男性)に固定 japanese
        sreq.VoiceId = VoiceId.Takumi;
        SynthesizeSpeechResponse sres = client.SynthesizeSpeech(sreq);
        var response = client.DescribeVoices(new DescribeVoicesRequest{LanguageCode = "ja-JP"});
        List<Voice> voices = response.Voices; 
        foreach(var i in voices)
        {
            Debug.Log(i.Name);
        }

        //save voice
        using (var fileStream = File.Create(Application.persistentDataPath + "/" + fileName))
        {
            sres.AudioStream.CopyTo(fileStream);
            fileStream.Flush();
            fileStream.Close();
        }

        string uri = "file://" + Application.persistentDataPath + "/" + fileName;
        using (UnityWebRequest unityWebRequest = UnityWebRequestMultimedia.GetAudioClip(uri, AudioType.OGGVORBIS))
        {
            yield return unityWebRequest.SendWebRequest();

            if (unityWebRequest.result == UnityWebRequest.Result.ConnectionError)
            {
                Debug.Log(unityWebRequest.error);
            }
            else
            {
                AudioClip audioClip = DownloadHandlerAudioClip.GetContent(unityWebRequest);
                audioSource.clip = audioClip;
                audioSource.Play();
            }
        }
    }
}

sorry. I had left out a lot of things from the description, but the conclusion was that the execution environment for the AWS SDK (like AWS.SDK.Core) needs to be .net standard, not .net framework... (Don't forget to mention that in your link.xml just in case)

0

There are 0 best solutions below