Partager via


Handling errors in speech apps for Windows Phone 8

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Although occasionally you'll encounter a managed exception when dealing with the speech feature, the majority of speech errors are returned in HResult format. You can use the debugger to view both the individual error code, and the error description, and you can use try-catch statements in your code to take corrective action.

This topic is a reference of speech-related errors, including HResult info and descriptions. If you're here to look up a specific error, the fastest solution is to use Ctrl+F to find the error string or code on the page.

This topic contains the following sections.

Handling the speech privacy policy error

When working with speech recognition, the most important error to handle relates to the speech privacy policy. Each time a speech recognition attempt occurs in an app, a privacy policy window appears. If the privacy policy is not accepted, you should ensure that your app handles the error accordingly.

The following code example shows one way you could handle the speech privacy policy error. In this example, a MessageBox control appears and prompts the user to accept the privacy policy.

private async void Reco1_Click(object sender, RoutedEventArgs e)
{
    try
    {
        // Start speech recognition.
        SpeechRecognitionResult recoResult = await myRecognizer.RecognizeAsync();

        // Display the recognized text.
        displayText.Text = "You said: \n\n" + recoResult.Text;
    }

    // Catch errors related to the recognition operation.
    catch (Exception err)
    {
        // Define a variable that holds the error for the speech recognition privacy policy. 
        // This value maps to the SPERR_SPEECH_PRIVACY_POLICY_NOT_ACCEPTED error, 
        // as described in the Windows.Phone.Speech.Recognition error codes section later on.
        const int privacyPolicyHResult = unchecked((int)0x80045509);

        // Check whether the error is for the speech recognition privacy policy.
        if (err.HResult == privacyPolicyHResult)
        {
            MessageBox.Show("You will need to accept the speech privacy policy in order to use speech recognition in this app.");
        }
        else
        {
            // Handle other types of errors here.
        }
    }
}

Windows.Phone.Speech.Recognition error codes

The following table lists error codes for the Windows.Phone.Speech.Recognition namespace.

Error and error code

Error description

SPERR_RECOERROR_NOSPEECH 0x80045501

No speech was detected during a recognition operation.

SPERR_RECOERROR_NOMATCH 0x80045502

Speech input could not be matched to an enabled grammar.

SPERR_RECOERROR_NETWORK_TIMEOUT 0x80045503

The network connection timed out.

SPERR_RECOERROR_NETWORK_UNAVAILABLE 0x80045504

The network connection is not available.

SPERR_GRAMMAR_DUP_NAME 0x80045505

The grammar set contains more than one grammar with the same name.

SPERR_GRAMMARSET_CANT_ADD 0x80045506

The grammar could not be added to the grammar set.

SPERR_GRAMMARSET_LOAD_CANCELED 0x80045507

An operation to load a grammar to a grammar set was cancelled.

SPERR_SYSTEM_CALL_INTERRUPTED 0x80045508

A speech operation was aborted by a system call, for example fast app switching or an incoming phone call.

SPERR_SPEECH_PRIVACY_POLICY_NOT_ACCEPTED 0x80045509

The speech privacy policy was not accepted before the first attempt to use speech recognition on the phone.

SPERR_AUDIO_LIMIT_EXCEEDED 0x8004550A

The audio of a speech input attempt exceeds the supported limit.

SPERR_NO_RULES_TO_ACTIVATE 0x8004550B

There are no active rules in any loaded grammars.

SPERR_WINRT_INTERNAL_ERROR 0x800455A0

Generic error that is not actionable by developers.

SPERR_WINRT_ALREADY_IN_LEX 0x800455A1

The word, pronunciation, or POS pair being added is already in lexicon.

SPERR_WINRT_NOT_IN_LEX 0x800455A2

The word does not exist in the lexicon.

SPERR_WINRT_RULE_NOT_DYNAMIC 0x800455A3

An attempt was made to modify a non-dynamic rule.

SPERR_WINRT_DUPLICATE_RULE_NAME 0x800455A4

A rule name was duplicated.

SPERR_WINRT_DUPLICATE_RESOURCE_NAME 0x800455A5

A resource name was duplicated for a given rule.

SPERR_WINRT_TOO_MANY_GRAMMARS 0x800455A6

Too many grammars have been loaded.

SPERR_WINRT_CIRCULAR_REFERENCE 0x800455A7

Circular reference in import rules of grammars.

SPERR_WINRT_INVALID_IMPORT 0x800455A8

A rule reference to an imported grammar that could not be resolved.

SPERR_WINRT_RULE_NAME_ID_CONFLICT 0x800455A9

A rule exists with matching IDs (names) but different names (IDs).

SPERR_WINRT_NO_RULES 0x800455AA

A grammar contains no top-level, dynamic, or exported rules. There is no possible way to activate or otherwise use any rule in this grammar.

SPERR_WINRT_CIRCULAR_RULE_REF 0x800455AB

Rule 'A' refers to a second rule 'B' which, in turn, refers to rule 'A'.

SPERR_WINRT_NOT_DYNAMIC_GRAMMAR 0x800455AC

Attempt was made to manipulate a non-dynamic grammar.

SPERR_WINRT_AMBIGUOUS_PROPERTY 0x800455AD

Cannot add ambiguous property.

SPERR_WINRT_EXPORT_DYNAMIC_RULE 0x800455AE

Exported rules cannot refer directly or indirectly to a dynamic rule.

SPERR_WINRT_WORDFORMAT_ERROR 0x800455AF

Incorrect word format, probably due to incorrect pronunciation string.

SPERR_WINRT_LANGID_MISMATCH 0x800455B1

An attempt to load a CFG grammar with a LANGID different than other loaded grammars.

SPERR_WINRT_NO_WORD_PRONUNCIATION 0x800455B2

The SR engine is unable to add this word to a grammar. The application may need to supply an explicit pronunciation for this word.

SPERR_WINRT_SML_GENERATION_FAIL 0x800455B3

The SML couldn't be generated. For example, the transformation xslt template is not well formed.

SPERR_WINRT_ROOTRULE_ALREADY_DEFINED 0x800455B4

There is already a root rule for this grammar Defining another root rule will fail.

SPERR_WINRT_UNSUPPORTED_PHONEME 0x800455B5

Unknown phoneme.

SPERR_WINRT_PHONEME_CONVERSION 0x800455B6

Cannot convert the phonemes to the specified phonetic alphabet.

SPERR_WINRT_NO_RULES_TO_ACTIVATE 0x800455B7

The grammar does not have any root or top-level active rules to activate.

SPERR_WINRT_LEX_INVALID_DATA 0x800455B8

The lexicon data is invalid or corrupted.

SPERR_WINRT_CFG_INVALID_DATA 0x800455B9

The data in the CFG grammar is invalid or corrupted.

SPERR_WINRT_SISR_ATTRIBUTES_NOT_ALLOWED 0x800455BA

Attributes are not allowed at the top level.

SPERR_WINRT_SISR_MIXED_NOT_ALLOWED 0x800455BB

Mixed content is not allowed at the top level.

SPERR_WINRT_UNSUPPORTED_LANG 0x800455BC

The requested language is not supported.

SPERR_WINRT_STRING_TOO_LONG 0x800455BD

The string is too long.

SPERR_WINRT_STRING_EMPTY 0x800455BE

The string cannot be empty.

SPERR_WINRT_NO_MORE_ITEMS 0x800455BF

When enumerating items, the requested index is greater than the count of items.

Speech recognition exceptions

In addition to the Windows.Phone.Speech.Recognition namespace error codes, you might encounter the following exceptions when working with speech recognition.

Exception

Description

InvalidFormatException

An SRGS grammar file reference by a speech recognizer has an invalid format.

InvalidOperationException

An operation is already in progress.

FileNotFoundException

An SRGS grammar file reference by a speech recognizer cannot be found.

UnauthorizedAccessException

A capability required by speech recognition has not been set.

Speech recognition status errors

When attempting speech recognition by calling the SpeechRecognizerUIRecognizeWithUIAsync()()() method, several errors could occur. For example, speech recognition might not be possible because the phone's speech feature is active. For a full list of these errors, see the SpeechRecognitionUIStatus enumeration.

Windows.Phone.Speech.Synthesis error codes

The following table lists error codes for the Windows.Phone.Speech.Synthesis namespace.

Error

Error code

Description

SPERR_SYSTEM_CALL_INTERRUPTED

0x80045508

A speech operation was aborted by a system call, for example fast app switching or an incoming phone call.

SPERR_WINRT_INTERNAL_ERROR

0x800455A0

Generic error that is not actionable by developers.

SPERR_WINRT_ALREADY_IN_LEX

0x800455A1

The word, pronunciation, or POS pair being added is already in lexicon.

SPERR_WINRT_NOT_IN_LEX

0x800455A2

The word does not exist in the lexicon.

SPERR_WINRT_UNSUPPORTED_PHONEME

0x800455B5

Unknown phoneme.

SPERR_WINRT_PHONEME_CONVERSION

0x800455B6

Cannot convert the phonemes to the specified phonetic alphabet.

SPERR_WINRT_LEX_INVALID_DATA

0x800455B8

The lexicon data is invalid or corrupted.

SPERR_WINRT_UNSUPPORTED_LANG

0x800455BC

The requested language is not supported.

SPERR_WINRT_STRING_TOO_LONG

0x800455BD

The string is too long.

SPERR_WINRT_STRING_EMPTY

0x800455BE

The string cannot be empty.

SPERR_WINRT_NO_MORE_ITEMS

0x800455BF

When enumerating items, the requested index is greater than the count of items.

Speech synthesis exceptions

In addition to the Windows.Phone.Speech.Synthesis namespace error codes, you might encounter the following exceptions when working with speech synthesis.

Exception

Description

InvalidFormatException

An SSML prompt file referenced by a speech synthesizer has an invalid format.

InvalidOperationException

An operation is already in progress.

FileNotFoundException

An SSML prompt file referenced by a speech synthesizer cannot be found.

UnauthorizedAccessException

A capability required by speech recognition has not been set.

Windows.Phone.Speech.VoiceCommands error codes

The following table lists error codes for the Windows.Phone.Speech.VoiceCommands namespace. The majority of these errors relate to the Voice Command Definition (VCD) file schema. For more info about the correct schema for VCD files, see Voice command element and attribute reference for Windows Phone 8.

Error

Error code

Description

SPERR_VC_EXPECTED_VOICE_COMMANDS_ELEMENT

0x80045550

The VoiceCommands element is not located directly after the xml element declaration.

SPERR_VC_INVALID_VOICE_COMMANDS_ELEMENT

0x80045551

The VoiceCommands element is invalid.

SPERR_VC_EXPECTED_XML_DECLARATION

0x80045552

The VCD file does not start with an xml element declaration.

SPERR_VC_INVALID_XML_ATTRIBUTES

0x80045553

The xml element declaration does not contain both the version and encoding attributes.

SPERR_VC_INVALID_XML_VERSION

0x80045554

The xml element does not have a version attribute of \"1.0\".

SPERR_VC_INVALID_XML_ENCODING

0x80045555

The xml element does not have an encoding attribute of \"utf-8\".

SPERR_VC_INVALID_NAMESPACE

0x80045556

The VoiceCommands element does not have the namespace xmlns attribute of \"http//schemas.microsoft.com/voicecommands/1.0\".

SPERR_VC_EXPECTED_COMMANDSET

0x80045557

The VoiceCommands element is empty.

SPERR_VC_INVALID_COMMANDSET

0x80045558

The VoiceCommands element contains content other than CommandSet elements.

SPERR_VC_INVALID_COMMANDSET_ATTRIBUTES

0x80045559

The CommandSet element does not specify an xmllang attribute, or any attribute within the CommandSet element is invalid.

SPERR_VC_EXPECTED_PREFIX_OR_EXAMPLE

0x8004555A

The CommandSet element is empty.

SPERR_VC_INVALID_PREFIX

0x8004555B

The CommandPrefix element is invalid.

SPERR_VC_EXPECTED_COMMANDSET_EXAMPLE

0x8004555C

The CommandSet element does not contain an Example element.

SPERR_VC_INVALID_COMMANDSET_EXAMPLE

0x8004555D

The Example element for the CommandSet element is invalid.

SPERR_VC_EXPECTED_COMMAND

0x8004555E

The CommandSet element does not contain any Command elements.

SPERR_VC_INVALID_COMMAND

0x8004555F

The Command element for the CommandSet element is invalid.

SPERR_VC_INVALID_COMMAND_ATTRIBUTES

0x80045560

The Command element does not specify a Name attribute; or, any attribute within the Command element is invalid.

SPERR_VC_EXPECTED_COMMAND_OR_PHRASELIST

0x80045561

The CommandSet element contains content other than Command or PhraseList elements.

SPERR_VC_EXPECTED_COMMAND_EXAMPLE

0x80045562

The Command element does not contain an Example element.

SPERR_VC_INVALID_COMMAND_EXAMPLE

0x80045563

The Example element for the Command element is invalid.

SPERR_VC_EXPECTED_LISTENFOR

0x80045564

The Command element does not specify any ListenFor elements.

SPERR_VC_INVALID_LISTENFOR

0x80045565

The ListenFor element is invalid.

SPERR_VC_EXPECTED_FEEDBACK

0x80045566

The Feedback element is not directly located after the ListenFor element.

SPERR_VC_INVALID_FEEDBACK

0x80045567

The Feedback element is invalid.

SPERR_VC_EXPECTED_NAVIGATE

0x80045568

The Navigate element is not directly located after the Feedback element.

SPERR_VC_INVALID_NAVIGATE

0x80045569

The Navigate element is invalid.

SPERR_VC_INVALID_NAVIGATE_ATTRIBUTES

0x8004556A

An attribute specified by the Navigate element is invalid.

SPERR_VC_EXPECTED_PHRASELIST

0x8004556B

A CommandSet element contains a PhraseList element, followed by something other than a PhraseList element.

SPERR_VC_INVALID_PHRASELIST

0x8004556C

The PhraseList element is invalid.

SPERR_VC_INVALID_PHRASELIST_ATTRIBUTES

0x8004556D

The PhraseList element does not specify a Label attribute, or any attribute within the PhraseList element is invalid.

SPERR_VC_EXPECTED_PHRASELIST_ITEM

0x8004556E

The PhraseList element contains content other than Item elements.

SPERR_VC_INVALID_PHRASELIST_ITEM

0x8004556F

The Item element is invalid.

SPERR_VC_TOO_MANY_PHRASELIST_ITEMS

0x80045570

There are too many Item elements.

SPERR_VC_INVALID_NODE

0x80045571

This Xml node was not expected.

SPERR_VC_TOO_MANY_PHRASELISTS

0x80045572

There are too many PhraseList elements.

SPERR_VC_UNEXPECTED_END_OF_FILE

0x80045573

The VCD file ended unexpectedly.

SPERR_VC_EXPECTED_END_OF_FILE

0x80045574

The VCD file does not end after the VoiceCommands element closing tag.

SPERR_VC_INVALID_STRING_LENGTH

0x80045575

A string in the VCD file is too long or too short.

SPERR_VC_INVALID_XML_DOCUMENT

0x80045576

The VCD file is an invalid XML file.

SPERR_VC_INVALID_FEEDBACK_LABEL_NO_SEMANTICS

0x80045577

A PhraseList element referenced in a Feedback element has the Disambiguate attribute set to \"false\".

SPERR_VC_INVALID_PATTERN_REFERENCED_LABEL_NOT_FOUND

0x80045578

A ListenFor or Feedback element refers to a PhraseList element by using a Label attribute, but that Label attribute does not map to an existing PhraseList element.

SPERR_VC_INVALID_PHRASELIST_NEVER_USED

0x80045579

A PhraseList element was defined but never used.

SPERR_VC_INVALID_FEEDBACK_LABEL_NOT_IN_ALL_LISTENFORS

0x80045580

A PhraseList element that is referenced in a Feedback element is not referenced in all ListenFor elements for the corresponding Command element.

SPERR_VC_TOO_MANY_LISTENFORS

0x80045581

There are too many ListenFor elements.

SPERR_VC_TOO_MANY_COMMANDSETS

0x80045582

There are too many CommandSet elements.

SPERR_VC_TOO_MANY_COMMANDS

0x80045583

There are too many Command elements.

SPERR_VC_INVALID_COMMANDSET_LANGUAGE

0x80045584

The requested language attribute value is not supported for a CommandSet element.

SPERR_VC_DUPLICATE_COMMANDSET_LANGUAGE

0x80045585

There is already a CommandSet element with the specified language attribute value.

For info about the correct schema for VCD files, see Voice command element and attribute reference for Windows Phone 8.