Page 48 - MSDN Magazine, February 2018
P. 48
Figure 2 An Example of Running the “Hello, World!” Script on iPhone (Left) and on Android (Right)
specified as ISO 639-1 code for the language name and ISO 3166-1 alpha-2 for the country code (for example. “en-US” for English, U.S., “es-MX” for Spanish, Mexico, “pt-BR”, for Portuguese, Brazil, and so on).
The signature of the voice recognition callback func- tion is the following:
function voice_recog(errorStatus, recognized)
The errorStatus argument will be an empty string on success and a description of the error on failure. If the function is successful, the recognized word is passed as the second parameter. If not, an alert dialog will be shown to the user (implemented as a UIAlertController on iOS and as an AlertDialog.Builder on Android). If the voice recognition is successful, the text-to-speech func- tion Speak will be called. It has the following signature:
Speak(wordToPronounce, voice = "en-US");
The results of running the script in Figure 1 are shown in Figure 2. The figure on the left, representing an iPhone, shows successful voice recognition—when a pronounced word was recognized. The figure on the right, representing an Android, shows a failure, when there’s no microphone installed on the system (a com- mon case when using a simulator).
Figure 3 General Structure of a Xamarin Project with CSCS Scripting 44 msdn magazine
C#