diff --git a/Assets/Scripts/APIManager.cs b/Assets/Scripts/APIManager.cs index 39d6cf8..4961620 100644 --- a/Assets/Scripts/APIManager.cs +++ b/Assets/Scripts/APIManager.cs @@ -28,8 +28,14 @@ public void SendPrompt() public void Record() { - - StartCoroutine("hi!"); + if (voiceManager != null) + { + voiceManager.StartRecording(); + } + else + { + Debug.LogWarning("APIManager: Cannot record — voiceManager is not assigned."); + } } private IEnumerator SendDataToGas() @@ -58,14 +64,16 @@ private IEnumerator SendDataToGas() } else { - response = "There was an error"; + response = $"Request failed: {www.error}"; + Debug.LogError($"APIManager: {response}"); } - + Debug.Log(response); responseText.text = response; - // Speak the new AI response - if (ttsManager != null && !string.IsNullOrEmpty(response)) + // Speak the AI response only on success + if (www.result == UnityWebRequest.Result.Success + && ttsManager != null && !string.IsNullOrEmpty(response)) { ttsManager.Speak(response); } @@ -73,5 +81,9 @@ private IEnumerator SendDataToGas() // Hide spinner if (spinner != null) spinner.SetActive(false); + + // Re-enable send button + if (sendButton != null) + sendButton.interactable = true; } } diff --git a/Assets/Scripts/Whisper&TTS/ARAppVoiceManager.cs b/Assets/Scripts/Whisper&TTS/ARAppVoiceManager.cs index 7ebffe6..6994d46 100644 --- a/Assets/Scripts/Whisper&TTS/ARAppVoiceManager.cs +++ b/Assets/Scripts/Whisper&TTS/ARAppVoiceManager.cs @@ -126,6 +126,14 @@ private void ResetUI() recordButton.interactable = true; } + /// + /// Public entry point for starting voice recording from external scripts. + /// + public void StartRecording() + { + OnRecordButtonPressed(); + } + public string GetLastTranscription() { return lastTranscription;