Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/5.0] Backport System.Speech to compat pack #46729

Merged
merged 11 commits into from
Jan 14, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ internal enum SAPIErrorCodes
SP_NO_PARSE_FOUND = 0x0004502c,
SP_WORD_EXISTS_WITHOUT_PRONUNCIATION = 0x00045037, // 282679

SPERR_FIRST = -2147201023, // 0x80045001
SPERR_LAST = -2147200890, // 0x80045086
SPERR_FIRST = -2147201023, // 0x80045001 == SPERR_UNINITIALIZED
SPERR_LAST = -2147200877, // 0x80045093 == SPERR_VOICE_NOT_FOUND

STG_E_FILENOTFOUND = -2147287038, // 0x80030002
CLASS_E_CLASSNOTAVAILABLE = -2147221231, // 0x80040111
Expand Down
70 changes: 68 additions & 2 deletions src/libraries/System.Speech/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,43 @@ Possible constructors are: '{2}'.</value>
<value>The local recognizer cannot activate a rule, dictation, or other stream until it is initialized. Call SetInput first.</value>
</data>
<data name="SapiErrorUnused0" xml:space="preserve">
<value>Error code not used.</value>
<value></value> <!-- SAPI does not use this code -->
</data>
<data name="SapiErrorUnused1" xml:space="preserve">
<value></value> <!-- SAPI does not use this code -->
</data>
<data name="SapiErrorUnused2" xml:space="preserve">
<value></value> <!-- SAPI does not use this code -->
</data>
<data name="SapiErrorUnused3" xml:space="preserve">
<value></value> <!-- SAPI does not use this code -->
</data>
<data name="SapiErrorUnused4" xml:space="preserve">
<value></value> <!-- SAPI does not use this code -->
</data>
<data name="SapiErrorUnused5" xml:space="preserve">
<value></value> <!-- SAPI does not use this code -->
</data>
<data name="SapiErrorUnused6" xml:space="preserve">
<value></value> <!-- SAPI does not use this code -->
</data>
<data name="SapiErrorUnused7" xml:space="preserve">
<value></value> <!-- SAPI does not use this code -->
</data>
<data name="SapiErrorUnused8" xml:space="preserve">
<value></value> <!-- SAPI does not use this code -->
</data>
<data name="SapiErrorUnused9" xml:space="preserve">
<value></value> <!-- SAPI does not use this code -->
</data>
<data name="SapiErrorUnused10" xml:space="preserve">
<value></value> <!-- SAPI does not use this code -->
</data>
<data name="SapiErrorUnused11" xml:space="preserve">
<value></value> <!-- SAPI does not use this code -->
</data>
<data name="SapiErrorUnused12" xml:space="preserve">
<value></value> <!-- SAPI does not use this code -->
</data>
<data name="SapiErrorNotSupportedLang" xml:space="preserve">
<value>The requested language is not supported.</value>
Expand Down Expand Up @@ -1232,7 +1268,7 @@ Possible constructors are: '{2}'.</value>
<value>The user has chosen to disable speech from running on the machine, or the system is not set up to run speech.</value>
</data>
<data name="SapiErrorRecognizerNotFound" xml:space="preserve">
<value>No recognizer is installed. </value>
<value>No recognizer is installed.</value>
</data>
<data name="SapiErrorAudioNotFound" xml:space="preserve">
<value>No audio device is installed.</value>
Expand Down Expand Up @@ -1270,4 +1306,34 @@ Possible constructors are: '{2}'.</value>
<data name="SapiErrorNotSupportedForInprocRecognizer" xml:space="preserve">
<value>The method called is not supported for the in-process recognizer.</value>
</data>
<data name="SapiLexInvalidData" xml:space="preserve">
<value>The lexicon data is invalid or corrupted.</value>
</data>
<data name="SapiLexUnexpectedFormat" xml:space="preserve">
<value>The lexicon is not in the expected format.</value>
</data>
<data name="SapiNonWordTransition" xml:space="preserve">
<value>One of the parse transitions is not a word transition.</value>
</data>
<data name="SapiSisrAttributesNotAllowed" xml:space="preserve">
<value>Attributes are not allowed at the top level.</value>
</data>
<data name="SapiSisrMixedNotAllowed" xml:space="preserve">
<value>Mixed content is not allowed at the top level.</value>
</data>
<data name="SapiStringEmpty" xml:space="preserve">
<value>The string cannot be empty.</value>
</data>
<data name="SapiStringTooLong" xml:space="preserve">
<value>The string is too long.</value>
</data>
<data name="SapiVoiceNotFound" xml:space="preserve">
<value>No given voice is found.</value>
</data>
<data name="SapiErrorOverload" xml:space="preserve">
<value>The operation cannot be carried out due to overload and should be attempted again.</value>
</data>
<data name="SapiConfigInvalidData" xml:space="preserve">
<value>The data in the CFG grammar is invalid or corrupted.</value>
</data>
</root>
54 changes: 32 additions & 22 deletions src/libraries/System.Speech/src/SRID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ internal enum SRID
NumberOfSamplesInvalid,
// Do not change ordering of codes below here; they correspond to the
// numerical codes in sperror.h, from SPERR_UNINITIALIZED onwards.
SapiErrorUninitialized,
SapiErrorUninitialized, // 0x80045001 == SPERR_UNINITIALIZED == SPERR_FIRST
SapiErrorAlreadyInitialized,
SapiErrorNotSupportedFormat,
SapiErrorInvalidFlags,
Expand Down Expand Up @@ -351,10 +351,10 @@ internal enum SRID
SapiErrorNotTopLevelRule,
SapiErrorNoRuleActive,
SapiErrorLexRequiresCookie,
SapiErrorStreamUninitialized,
SapiErrorUnused0,
SapiErrorNotSupportedLang,
SapiErrorVoicePaused,
SapiErrorStreamUninitialized, // 0x80045057
SapiErrorUnused0, // 0x80045058 is not used by SAPI, but it keeps counting
SapiErrorNotSupportedLang, // 0x80045059
SapiErrorVoicePaused, // 0x8004505a
SapiErrorAudioBufferUnderflow,
SapiErrorAudioStoppedUnexpectedly,
SapiErrorNoWordPronunciation,
Expand All @@ -368,10 +368,16 @@ internal enum SRID
SapiErrorAudioStopped,
SapiErrorRecoXMLGenerationFail,
SapiErrorSMLGenerationFail,
SapiErrorNotPromptVoice,
SapiErrorRootRuleAlreadyDefined,
SapiErrorScriptDisallowed,
SapiErrorRemoteCallTimedOutStart,
SapiErrorNotPromptVoice, // 0x80045068
SapiErrorRootRuleAlreadyDefined, // 0x80045069 == SPERR_ROOTRULE_ALREADY_DEFINED, then it skips 6
SapiErrorUnused1, // skipped
SapiErrorUnused2, // skipped
SapiErrorUnused3, // skipped
SapiErrorUnused4, // skipped
SapiErrorUnused5, // skipped
SapiErrorUnused6, // skipped
SapiErrorScriptDisallowed, // 0x80045070 == SPERR_SCRIPT_DISALLOWED
SapiErrorRemoteCallTimedOutStart, // 0x80045071
SapiErrorRemoteCallTimedOutConnect,
SapiErrorSecMgrChangeNotAllowed,
SapiErrorCompleteButExtendable,
Expand All @@ -389,18 +395,22 @@ internal enum SRID
NotSupported,
SapiErrorTopicNotAdaptable,
SapiErrorPhonemeConversion,
SapiErrorNotSupportedForInprocRecognizer
/* would continue as follows:
SPERR_OVERLOAD The operation cannot be carried out due to overload and should be attempted again.
SPERR_LEX_INVALID_DATA The lexicon data is invalid or corrupted.
SPERR_CFG_INVALID_DATA The data in the CFG grammar is invalid or corrupted // currently == SPERR_LAST
SPERR_LEX_UNEXPECTED_FORMAT The lexicon is not in the expected format.
SPERR_STRING_TOO_LONG The string is too long.
SPERR_STRING_EMPTY The string cannot be empty.
SPERR_NON_WORD_TRANSITION One of the parse transitions is not a word transition.
SPERR_SISR_ATTRIBUTES_NOT_ALLOWED Attributes are not allowed at the top level.
SPERR_SISR_MIXED_NOT_ALLOWED Mixed content is not allowed at the top level.
SPERR_VOICE_NOT_FOUND NO given voice is found
*/
SapiErrorNotSupportedForInprocRecognizer,
SapiErrorOverload,
SapiLexInvalidData,
SapiConfigInvalidData,
SapiLexUnexpectedFormat,
SapiStringTooLong, // 0x80045088
SapiStringEmpty, // 0x80045089 == SPERR_STRING_EMPTY, then it skips 6
SapiErrorUnused7, // skipped
SapiErrorUnused8, // skipped
SapiErrorUnused9, // skipped
SapiErrorUnused10, // skipped
SapiErrorUnused11, // skipped
SapiErrorUnused12, // skipped
SapiNonWordTransition, // 0x80045090 == SPERR_NON_WORD_TRANSITION
SapiSisrAttributesNotAllowed, // 0x80045091
SapiSisrMixedNotAllowed, // 0x80045092
SapiVoiceNotFound // 0x80045093 == SPERR_VOICE_NOT_FOUND == SPERR_LAST
}
}
31 changes: 30 additions & 1 deletion src/libraries/System.Speech/tests/SpeechRecognizerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,38 @@

namespace SampleSynthesisTests
{
[ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoNorServerCore))] // No SAPI on Nano or Server Core
[SkipOnMono("No SAPI on Mono")]
public static class SpeechRecognizerTests
{
[Fact]
private static bool RecognizerInstalledAndEnabled()
{
if (PlatformDetection.IsMonoRuntime ||
PlatformDetection.IsWindowsNanoServer ||
PlatformDetection.IsWindowsServerCore)
danmoseley marked this conversation as resolved.
Show resolved Hide resolved
{
return false;
}

try
{
using (SpeechRecognizer recognizer = new SpeechRecognizer())
{
_ = recognizer.State; // force initialization
}
}
catch (Exception ex) when (ex is PlatformNotSupportedException || ex is InvalidOperationException)
{
// PlatformNotSupportedException : No recognizer is installed.
// PlatformNotSupportedException : The user has chosen to disable speech from running on the machine, or the system is not set up to run speech.
// InvalidOperationException : No audio device is installed.
return false;
}

return true;
}

[ConditionalFact(nameof(RecognizerInstalledAndEnabled))]
[OuterLoop] // Pops UI
public static void SpeechRecognizer()
{
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Speech/tests/SynthesizeRecognizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void SpeechSynthesizerToSpeechRecognitionEngine()
}

[ConditionalFact(nameof(HasInstalledRecognizers))]
public void SpeechRecognizerInvalidInput()
public void SpeechRecognitionEngineInvalidInput()
{
using var ms = new MemoryStream();
ms.WriteByte(1);
Expand All @@ -67,7 +67,7 @@ public void SpeechRecognizerInvalidInput()
}

[ConditionalFact(nameof(HasInstalledRecognizers))]
public void SpeechRecognizerProperties()
public void SpeechRecognitionEngineProperties()
{
using (var rec = new SpeechRecognitionEngine())
{
Expand Down