-
[이슈관리] Unity에서 Google Speech API Asset의 C# Script 고치기CS/졸업 프로젝트(Duk to Me) 2023. 6. 26. 07:04반응형
상황
Unity와 연결하여 사용 중인 Google Speech API Asset(https://assetstore.unity.com/packages/tools/ai-integration/speech-recognition-using-google-cloud-vr-ar-mobile-desktop-pro-72625)에서 제공하는 C# Script에서 인식된 음성을 특정 텍스트와 비교하여 Matched 결과를 알 수 있도록 RecognizeSuccessEventHandler를 수정하려고 한다.
private void RecognizeSuccessEventHandler(RecognitionResponse recognitionResponse) { string transcript = recognitionResponse.ToString(); string scriptToMatch = "Hi, I'm good. I'm here to check in for my flight."; if (transcript.Equals(scriptToMatch, System.StringComparison.OrdinalIgnoreCase)) { Debug.Log("Success!"); // Perform actions when the script matches InsertRecognitionResponseInfo(recognitionResponse); } else { Debug.Log("Try again!"); // Perform actions when the script does not match InsertRecognitionResponseInfo(recognitionResponse); } }
현재는 마이크 테스트 했을 때, 비교하려는 텍스트가 정확히 인식되어 자막처리까지 잘 되고 있다. 하지만 인식된 텍스트가 Matched 되어 'Success!' Log 결과를 보여야 할 때도 'Try again!'만 출력하고 있다.
해결
위의 코드에서는 'transcript' 변수는 recognitionResponse(인식된 음성)를 ToString()으로 받고있는데, 이는 인식된 음성의 내용을 문자열 형태로 받는 게 아니라, 인식된 음성을 처리하는 Class명을 문자열로 받아오는 것이었다. recognitionResponse의 내용을 추출하는 코드로 고쳐야 했다. 또한 Trim()을 추가하여 문자열 내용의 앞뒤로 불필요한 공백을 제거하도록 했다.
private void RecognizeSuccessEventHandler(RecognitionResponse recognitionResponse) { string transcript = recognitionResponse.results[0].alternatives[0].transcript; string scriptToMatch = "Hi, I'm good. I'm here to check in for my flight."; if (transcript.Trim().Equals(scriptToMatch.Trim(), System.StringComparison.OrdinalIgnoreCase)) { Debug.Log("Success!"); // Perform actions when the script matches InsertRecognitionResponseInfo(recognitionResponse); } else { Debug.Log("Try again!"); // Perform actions when the script does not match InsertRecognitionResponseInfo(recognitionResponse); } }
이제는 마이크 테스트 했을 때 비교하려는 텍스트와 Matched 되었을 때 결과와 실패했을 때 결과가 잘 나온다.
반응형'CS > 졸업 프로젝트(Duk to Me)' 카테고리의 다른 글
PlayFab 설명및 Unity와의 연동 (1) - UI 만들기, 기초설정, PlayFab 계정만들기 (0) 2023.09.17 Unity에서 여러 Scene으로부터 점수를 합산하여 내는 점수체계 C# Script 코드 쓰기 (0) 2023.08.16 [이슈관리] Google Cloud Text-to-Speech(TTS) API, 목소리 성별 바꾸기 (0) 2023.06.26 Google Cloud Text-to-Speech(TTS) API, Python으로 사용하기 (0) 2023.06.20 Google Cloud Speech-to-Text(STT) API 초기설정및 Python으로 사용하기 (0) 2023.06.20