Unhandled exception thrown by System.Speech when using it with SAPIForVOICEVOX

Open
#118,819 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
csharp

Research direction

Start by reproducing the crash with .NET 9 on Windows 10 using SAPIForVOICEVOX and the supplied sample, then inspect the dump around TtsProxySapi.GetOutputFormat, especially line 27 and the _sapiEngine.GetOutputFormat call. Confirm the failure path and whether it can be handled without terminating the process; done should include a regression test or documented verification for the affected voice.

Written by the indexing model from the issue text.

Description

area-System.Speech help wanted
Description

When using System.Speech with a voice provided by SAPIForVOICEVOX, System.Speech crashes the entire program. I have tried calling the SpeechSynthesizer.Speak and SpeechSynthesizer.SpeakAsync methods within a try-catch block to to at least prevent the crash, but it did not work.

Note that these voices function as expected when used with Windows Narrator without any issues whatsoever.

Here's the exception I get:
Unhandled exception at 0x00007FFA2C1B1A21 (ntdll.dll) in JL.exe.12272.dmp: Unknown __fastfail() status code: 0x0000000000000030.

Here's the dump file in case it's useful:
https://uploadnow.io/en/share?utm_source=P8d7wy4

Reproduction Steps
  1. Install VOICEVOX and SAPIForVOICEVOX. (Be sure to read the README of SAPIForVOICEVOX)

  2. Make sure the installed voice appears under:
    Windows Settings → Ease of Access → Narrator → Personalize Narrator's voice → Choose a voice dropdown menu.

  3. Turn on Windows Narrator to confirm that it works with a voice provided by SAPIForVOICEVOX.

  4. Try using the same voice with System.Speech, using code similar to the following:

    try
    {
        SpeechSynthesizer speechSynthesizer = new();
        speechSynthesizer.SelectVoice(voiceName); // The voice you've tested with Narrator, e.g., "VOICEVOX 四国めたん ささやき"
        speechSynthesizer.SetOutputToDefaultAudioDevice();
        speechSynthesizer.Speak("テスト");
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex.Message); // Program crashes before reaching this line, boohoo!
    }
    
  5. Observe the crash.

Expected behavior

System.Speech should be able to use voices provided by SAPIForVOICEVOX, just as Windows Narrator does, and it should definitely not cause the entire program to crash.

Actual behavior

System.Speech causes the entire program to crash, and even a try-catch block does not prevent the crash.

Regression?

No response

Known Workarounds

No response

Configuration

Which version of .NET is the code running on?

.NET 9

What OS and version, and what distro if applicable?

Windows 10, 22H2

What is the architecture (x64, x86, ARM, ARM64)?

x64

Other information

Upon examining the dump file, it seems that the exception occurs in the GetOutputFormat method of the TtsProxySapi class. The issue arises at line 27, where _sapiEngine.GetOutputFormat(ref pTargetFmtId, preferredFormat, out pOutputFormatId, out ppCoMemOutputWaveFormatEx) is invoked.

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.