Как использовать единство «audioclip VoiceClip» для прямого перехода к строковому пути в скрипте преобразования речи в текст (ibm watson unity sdk)? - PullRequest
0 голосов
/ 03 августа 2020

Я хочу направить аудиоклип VoiceClip на go в строковый путь. Или как использовать звук из «audioclip VoiceClip» вместо звука: File / ReadAllBytes и тип содержимого. Проверьте комментарии, чтобы увидеть, где, по моему мнению, это могло быть место. Я использую последнюю версию IBM Watson Unity Sdk из (https://github.com/watson-developer-cloud/unity-sdk). И вы можете легко настроить сцену, открыв пример сцены потоковой передачи и сняв флажок с пример сценария потоковой передачи. Затем добавляем в него этот скрипт.

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


public class SpeechToText : MonoBehaviour
{
    #region PLEASE SET THESE VARIABLES IN THE INSPECTOR
    [Space(10)]
    [Tooltip("The service URL (optional). This defaults to \"https://stream.watsonplatform.net/speech-to-text/api\"")]
    [SerializeField]
    private string _serviceUrl;
    [Tooltip("Text field to display the results of streaming.")]
    public Text ResultsField;
    [Header("IAM Authentication")]
    [Tooltip("The IAM apikey.")]
    [SerializeField]
    private string _iamApikey;

    [Header("Parameters")]
    // https://www.ibm.com/watson/developercloud/speech-to-text/api/v1/curl.html?curl#get-model
    [Tooltip("The Model to use. This defaults to en-US_BroadbandModel")]
    [SerializeField]
    private string _recognizeModel;
    #endregion

    private SpeechToTextService _service;
    SpeechRecognitionResults recognizeResponse = null;

    

//Problem: I want to use this audioclip VoiceClip to be directed into the string path , 
    [SerializeField] 
    AudioClip VoiceClip = null;
    string path1 = @"c:\Users\camer\Documents\UNITY PROJECTS\META FARMING\Assets\_CUSTOM\Audio\audio-file2.flac";

    


    void Start()
    {

        LogSystem.InstallDefaultReactors();
        Runnable.Run(CreateService());


    }


    private IEnumerator CreateService()
    {
        if (string.IsNullOrEmpty(_iamApikey))
        {
            throw new IBMException("Plesae provide IAM ApiKey for the service.");
        }

        IamAuthenticator authenticator = new IamAuthenticator(apikey: _iamApikey);

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

        _service = new SpeechToTextService(authenticator);
        if (!string.IsNullOrEmpty(_serviceUrl))
        {
            _service.SetServiceUrl(_serviceUrl);
        }
         

        _service.Recognize(
    callback: (DetailedResponse<SpeechRecognitionResults> response, IBMError error) =>
    {
        Log.Debug("SpeechToTextServiceV1", "Recognize result: {0}", response.Response);
        recognizeResponse = response.Result;
        
         
        ResultsField.text = response.Response;
    },


//This is where the audio goes:
    audio: File.ReadAllBytes(path1),
    contentType: "audio/flac",

    wordAlternativesThreshold: 0.9f,
    keywords: new List<string>()
    {
        "colorado",
        "tornado",
        "tornadoes"
    },
    keywordsThreshold: 0.5f
    
    );
        while (recognizeResponse == null)
        {
            yield return null;
        }
    }    
}



...