Question by
Tedesqui · Apr 29, 2020 at 08:16 PM ·
c#iosaiartificial intelligence
A little doubt about creating a Talking BOT that simulates AI, for iOS system using Unity.
Hello
I created a Talking BOT App for Android that simulates Artificial Intelligence. I created that without using Unity, but now I want to create this same App for iOS system too, and this time I will need to use Unity.
Here's the demo of the Android App working that I created, for you all understand what I want to do:
I confess that I'm a little beginner in C# language, but I added this C# file to my Application button, and I want to know what lines of code I need to add for when I say "Hello" an MP3 file will play and when I say "Good" Morning " another MP3 file will play (similar to what happens in my video)? :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using KKSpeech;
public class RecordingCanvas : MonoBehaviour {
public Button startRecordingButton;
public Text resultText;
void Start() {
if (SpeechRecognizer.ExistsOnDevice()) {
SpeechRecognizerListener listener = GameObject.FindObjectOfType<SpeechRecognizerListener>();
listener.onAuthorizationStatusFetched.AddListener(OnAuthorizationStatusFetched);
listener.onAvailabilityChanged.AddListener(OnAvailabilityChange);
listener.onErrorDuringRecording.AddListener(OnError);
listener.onErrorOnStartRecording.AddListener(OnError);
listener.onFinalResults.AddListener(OnFinalResult);
listener.onPartialResults.AddListener(OnPartialResult);
listener.onEndOfSpeech.AddListener(OnEndOfSpeech);
startRecordingButton.enabled = false;
SpeechRecognizer.RequestAccess();
} else {
resultText.text = "Sorry, but this device doesn't support speech recognition";
startRecordingButton.enabled = false;
}
}
public void OnFinalResult(string result) {
resultText.text = result;
}
public void OnPartialResult(string result) {
resultText.text = result;
}
public void OnAvailabilityChange(bool available) {
startRecordingButton.enabled = available;
if (!available) {
resultText.text = "Speech Recognition not available";
} else {
resultText.text = "Say something :-)";
}
}
public void OnAuthorizationStatusFetched(AuthorizationStatus status) {
switch (status) {
case AuthorizationStatus.Authorized:
startRecordingButton.enabled = true;
break;
default:
startRecordingButton.enabled = false;
resultText.text = "Cannot use Speech Recognition, authorization status is " + status;
break;
}
}
public void OnEndOfSpeech() {
startRecordingButton.GetComponentInChildren<Text>().text = "Start Recording";
}
public void OnError(string error) {
Debug.LogError(error);
resultText.text = "Something went wrong... Try again! \n [" + error + "]";
startRecordingButton.GetComponentInChildren<Text>().text = "Start Recording";
}
public void OnStartRecordingPressed() {
if (SpeechRecognizer.IsRecording()) {
SpeechRecognizer.StopIfRecording();
startRecordingButton.GetComponentInChildren<Text>().text = "Start Recording";
} else {
SpeechRecognizer.StartRecording(true);
startRecordingButton.GetComponentInChildren<Text>().text = "Stop Recording";
resultText.text = "Say something :-)";
}
}
}
Comment