Unityで会話をマイクで集音してテキストにするアプリを作りたく
AzureのSpeech SDKを使おうとしたところ下記エラーが出ました。
行った事)
1、Azureのアカウント作成
2、サブスクリプション キーの取得
3、Speech SDKのインポート
4、コードの記述(下記)
4のコードの記述をしたところ下記のエラーが出ました。
「アセンブリ参照がありません」とはどういうことでしょうか?
またどうすればエラーが解消されるでしょうか?
環境)
PC: mac
Unity2018.2
言語:C#
Assets/Scripts/HelloWorld.cs(3,17): error CS0234: The type or namespace name 'CognitiveServices' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
きちんとインポートもされています。
SpeechToTextScript.cs
using UnityEngine; using UnityEngine.UI; using Microsoft.CognitiveServices.Speech; #if PLATFORM_ANDROID using UnityEngine.Android; #endif public class SpeechToTextScript : MonoBehaviour { // Hook up the two properties below with a Text and Button object in your UI. public Text outputText; public Button startRecoButton; private object threadLocker = new object(); private bool waitingForReco; private string message; private bool micPermissionGranted = false; #if PLATFORM_ANDROID private Microphone mic; #endif public async void ButtonClick() { var config = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion"); // Make sure to dispose the recognizer after use! using (var recognizer = new SpeechRecognizer(config)) { lock (threadLocker) { waitingForReco = true; } var result = await recognizer.RecognizeOnceAsync().ConfigureAwait(false); // Checks result. string newMessage = string.Empty; if (result.Reason == ResultReason.RecognizedSpeech) { newMessage = result.Text; } else if (result.Reason == ResultReason.NoMatch) { newMessage = "NOMATCH: Speech could not be recognized."; } else if (result.Reason == ResultReason.Canceled) { var cancellation = CancellationDetails.FromResult(result); newMessage = $"CANCELED: Reason={cancellation.Reason} ErrorDetails={cancellation.ErrorDetails}"; } lock (threadLocker) { message = newMessage; waitingForReco = false; } } } void Start() { if (outputText == null) { UnityEngine.Debug.LogError("outputText property is null! Assign a UI Text element to it."); } else if (startRecoButton == null) { message = "startRecoButton property is null! Assign a UI Button to it."; UnityEngine.Debug.LogError(message); } else { // Continue with normal initialization, Text and Button objects are present. #if PLATFORM_ANDROID message = "Waiting for mic permission"; if (!Permission.HasUserAuthorizedPermission(Permission.Microphone)) { Permission.RequestUserPermission(Permission.Microphone); } #else micPermissionGranted = true; message = "Click button to recognize speech"; #endif startRecoButton.onClick.AddListener(ButtonClick); } } void Update() { #if PLATFORM_ANDROID if (!micPermissionGranted && Permission.HasUserAuthorizedPermission(Permission.Microphone)) { micPermissionGranted = true; message = "Click button to recognize speech"; } #endif lock (threadLocker) { if (startRecoButton != null) { startRecoButton.interactable = !waitingForReco && micPermissionGranted; } if (outputText != null) { outputText.text = message; } } } }

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/22 20:22