Build a speech recognizer on iOS

Photo by Omid Armin on Unsplash

Choose the best library for your needs

Speech to text

Libraries providing speech to text

Hotword recognition

Libraries used to recognize hotwords

No longer available libraries

Using Speech to Text

public Action<string> onResultsCallback;
public Action<string> onFinalResultCallback;
// ...
public void onResults(string _results)
{
if (onFinalResultCallback != null)
onFinalResultCallback(_results);
}
public void onResults(string _results)
{
if (onResultsCallback != null)
onResultsCallback(_results);
}
if (result.isFinal) {
// Stop the recognition
[inputNode removeTapOnBus:0];
[audioEngine stop];
[recognitionRequest endAudio];
// Call the "OnFinalResult" method
UnitySendMessage(
"SpeechToText",
"onFinalResult",
[transcriptText UTF8String]);
} else {
// Call the "OnResults" method
UnitySendMessage(
"SpeechToText",
"onResults",
[transcriptText UTF8String]);
}
if (isStarted)
{
recognizer.StartRecording();
}
public void OnResults(string message)
{
bool isCommand = IsACommandPhrase(message, langCode);
if (isCommand)
{
recognizer.StopRecording();
}
}

Go further… and gain in accuracy!

Using Hotword recognition (with Porcupine)

// Get path of model file depending on the language used
string pvPath = pvPaths[langCode];
// Get path of the keyword which has to be recognized
string
keywordPath = keywordPaths[langCode]
porcupineManager = PorcupineManager.FromKeywordPaths(
keywordPath,
OnResult,
pvPath
);

Final words

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store