Unity native speech recognition/no plug-ins/can be offline/no need for online speech recognition
Just upload the code and make sure your device is connected to the microphone. Then hang the following code directly on the empty object in the scene and run it.
using System. Collections ;
using System. Collections. Generic ;
using UnityEngine ;
using UnityEngine. Windows. Speech ;
public class SpeechRecognition : MonoBehaviour
{
private PhraseRecognizer m_PhraseRecognizer;
public string [ ] keywords = {
} ;
public ConfidenceLevel m_confidenceLevel = ConfidenceLevel. Medium;
void Start ( )
{
if ( m_PhraseRecognizer == null )
{
m_PhraseRecognizer = new KeywordRecognizer ( keywords, m_confidenceLevel) ;
m_PhraseRecognizer. OnPhraseRecognized += M_PhraseRecognizer_OnPhraseRecognized;
m_PhraseRecognizer. Start ( ) ;
}
}
private void M_PhraseRecognizer_OnPhraseRecognized ( PhraseRecognizedEventArgs args)
{
_SpeechRecognition ( args. text) ;
print ( args. text) ;
}
private void OnDestroy ( )
{
if ( m_PhraseRecognizer != null )
m_PhraseRecognizer. Dispose ( ) ;
}
void _SpeechRecognition ( string msg)
{
switch ( msg)
{
case "你好你好" :
Debug. Log ( "我在,你说" ) ;
break ;
case "XXXXX" :
Debug. Log ( "XXXXX" ) ;
break ;
default :
break ;
}
}
}