locked
SpeechSynthesizer.SynthesizeSsmlToStreamAsync Access Violations

    Question

  • Hi,

    My C# Windows Store app makes extensive use of SpeechSynthesisStream.SynthesizeSsmlToStreamAsync to read content back to my users.  I've found in practice that I get fairly frequent A/Vs during speech synthesis, especially if I don't take special precautions mentioned in http://stackoverflow.com/questions/14111456/text-to-speech-sapi5-accessviolationexception-when-using-another-voice.  Adding a GC.Collect seems to make the crashes less frequent and using a unique MediaElement for each playback seems to nearly mitigate the issue but I'm still seeing an unacceptably large number of crashes related to this issue.  In the event viewer I usually see two errors:

    Faulting application name: ***.Windows.exe, version: 1.0.0.0, time stamp: 0x54af32e5
    Faulting module name: Windows.Media.SpeechSynthesis.dll, version: 6.3.9600.16384, time stamp: 0x521574c9
    Exception code: 0xc0000005
    Fault offset: 0x00015374
    Faulting process id: 0xc04

    and the second

    Application: ***.Windows.exe
    Framework Version: v4.0.30319
    Description: The process was terminated due to an unhandled exception.
    Exception Info: exception code c0000005, exception address 0F975374

    I have a dump available as well and ran !analyze on it:

    0:030> !analyze -v
    *******************************************************************************
    *                                                                             *
    *                        Exception Analysis                                   *
    *                                                                             *
    *******************************************************************************

    *** WARNING: Unable to verify checksum for Windows.Media.ni.dll
    *** ERROR: Module load completed but symbols could not be loaded for Windows.Media.ni.dll
    *** WARNING: Unable to verify checksum for Windows.UI.Xaml.ni.dll
    *** ERROR: Module load completed but symbols could not be loaded for Windows.UI.Xaml.ni.dll
    *** WARNING: Unable to verify checksum for System.ni.dll

    FAULTING_IP:
    Windows_Media_SpeechSynthesis!Microsoft::WRL::Details::RuntimeClass<Microsoft::WRL::Details::InterfaceList<Windows::Foundation::IAsyncOperation<Windows::Media::SpeechSynthesis::SpeechSynthesisStream *>,Microsoft::WRL::Details::InterfaceList<Microsoft::WRL::Cl+11
    0fa947ef f00fc108        lock xadd dword ptr [eax],ecx

    EXCEPTION_RECORD:  ffffffff -- (.exr 0xffffffffffffffff)
    ExceptionAddress: 0fa947ef (Windows_Media_SpeechSynthesis!Microsoft::WRL::Details::RuntimeClass<Microsoft::WRL::Details::InterfaceList<Windows::Foundation::IAsyncOperation<Windows::Media::SpeechSynthesis::SpeechSynthesisStream *>,Microsoft::WRL::Details::InterfaceList<Microsoft::WRL::CloakedIid<ISpeakAsyncActionInternal>,Microsoft::WRL::Details::InterfaceList<Windows::Internal::AsyncBaseFTM<Windows::Foundation::IAsyncOperationCompletedHandler<Windows::Media::SpeechSynthesis::SpeechSynthesisStream *>,1,Microsoft::WRL::AsyncOptions<-1,0,GUID_CAUSALITY_WINDOWS_PLATFORM_ID,2> >,Microsoft::WRL::Details::Nil> > >,Microsoft::WRL::RuntimeClassFlags<3>,1,1,0>::AddRef+0x00000011)
       ExceptionCode: c0000005 (Access violation)
      ExceptionFlags: 00000000
    NumberParameters: 2
       Parameter[0]: 00000001
       Parameter[1]: 0000000c
    Attempt to write to address 0000000c

    CONTEXT:  00000000 -- (.cxr 0x0;r)
    eax=00000000 ebx=00000000 ecx=00000001 edx=0000007c esi=00000003 edi=00000003
    eip=770acf2c esp=10eae658 ebp=10eae7e0 iopl=0         nv up ei pl nz na po nc
    cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000202
    ntdll!NtWaitForMultipleObjects+0xc:
    770acf2c c21400          ret     14h

    DEFAULT_BUCKET_ID:  WRONG_SYMBOLS

    PROCESS_NAME:  ***.exe

    ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%08lx referenced memory at 0x%08lx. The memory could not be %s.

    EXCEPTION_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%08lx referenced memory at 0x%08lx. The memory could not be %s.

    EXCEPTION_PARAMETER1:  00000001

    EXCEPTION_PARAMETER2:  0000000c

    WRITE_ADDRESS:  0000000c

    FOLLOWUP_IP:
    Windows_Media_SpeechSynthesis!Microsoft::WRL::Details::RuntimeClass<Microsoft::WRL::Details::InterfaceList<Windows::Foundation::IAsyncOperation<Windows::Media::SpeechSynthesis::SpeechSynthesisStream *>,Microsoft::WRL::Details::InterfaceList<Microsoft::WRL::Cl+11
    0fa947ef f00fc108        lock xadd dword ptr [eax],ecx

    NTGLOBALFLAG:  0

    APPLICATION_VERIFIER_FLAGS:  0

    APP:  ***.exe

    ANALYSIS_VERSION: 6.3.9600.16384 (debuggers(dbg).130821-1623) amd64fre

    MANAGED_STACK: !dumpstack -EE
    No export dumpstack found

    MANAGED_BITNESS_MISMATCH:
    Managed code needs matching platform of sos.dll for proper analysis. Use 'x86' debugger.

    PRIMARY_PROBLEM_CLASS:  WRONG_SYMBOLS

    BUGCHECK_STR:  APPLICATION_FAULT_WRONG_SYMBOLS

    LAST_CONTROL_TRANSFER:  from 720811c9 to 0fa947ef

    STACK_TEXT: 
    10eaf324 720811c9 0b9d6848 720810aa bd303a3d Windows_Media_SpeechSynthesis!Microsoft::WRL::Details::RuntimeClass<Microsoft::WRL::Details::InterfaceList<Windows::Foundation::IAsyncOperation<Windows::Media::SpeechSynthesis::SpeechSynthesisStream *>,Microsoft::WRL::Details::InterfaceList<Microsoft::WRL::CloakedIid<ISpeakAsyncActionInternal>,Microsoft::WRL::Details::InterfaceList<Windows::Internal::AsyncBaseFTM<Windows::Foundation::IAsyncOperationCompletedHandler<Windows::Media::SpeechSynthesis::SpeechSynthesisStream *>,1,Microsoft::WRL::AsyncOptions<-1,0,GUID_CAUSALITY_WINDOWS_PLATFORM_ID,2> >,Microsoft::WRL::Details::Nil> > >,Microsoft::WRL::RuntimeClassFlags<3>,1,1,0>::AddRef+0x11
    10eaf32c 720810aa bd303a3d 0b9d6848 00000be7 clr!SafeAddRefPreemp+0x1b
    10eaf36c 72081189 00000001 7121a778 bd303af5 clr!RCW::CreateRCWInternal+0x97
    10eaf3a4 72080d35 00000001 7121a778 bd303d19 clr!RCW::CreateRCW+0x2b
    10eaf448 7208139a 00000000 10eaf478 10eaf59c clr!COMInterfaceMarshaler::CreateObjectRef+0xb7
    10eaf518 72080062 10eaf59c 30baa1c0 00000000 clr!COMInterfaceMarshaler::FindOrCreateObjectRefInternal+0x278
    10eaf9d8 720807e0 00000000 30baa1c0 00000005 clr!GetObjectRefFromComIP+0x37d
    10eaf9f8 7208073d 30baa1c0 00000000 00000025 clr!UnmarshalObjectFromInterface+0x3c
    10eafa9c 30b932f5 00000025 00000000 30b40100 clr!StubHelpers::InterfaceMarshaler__ConvertToManaged+0xeb
    WARNING: Stack unwind information not available. Following frames may be wrong.
    10eafacc 71f92a79 00000001 10eafba4 720b1896 Windows_Media_ni+0x932f5
    10eafaf0 72085a3e 30b932d0 30b40100 10eafb84 clr!COMToCLRDispatchHelper+0x6b
    10eafb5c 0fa96273 00000001 00000000 0b9d6848 clr!COMToCLRWorker+0x3e6
    10eafbb0 0fa96cf6 0b9588e8 0f5e1228 10eafbe0 Windows_Media_SpeechSynthesis!Windows::Media::SpeechSynthesis::Internal::ThreadpoolDelegateHelper<Windows::Foundation::IAsyncOperationCompletedHandler<Windows::Media::SpeechSynthesis::SpeechSynthesisStream *>,Windows::Foundation::IAsyncOperation<Windows::Media::SpeechSynthesis::SpeechSynthesisStream *> *>::CallHandlerOnThread+0x171
    10eafbc0 0f5e4a29 0b9588e8 13a40770 144cd110 Windows_Media_SpeechSynthesis!Microsoft::WRL::Details::InvokeHelper<Microsoft::WRL::Implements<Microsoft::WRL::RuntimeClassFlags<2>,Windows::System::Threading::IWorkItemHandler,Microsoft::WRL::FtmBase,Microsoft::WRL::Details::Nil,Microsoft::WRL::Details::Nil,Microsoft::WRL::Details::Nil,Microsoft::WRL::Details::Nil,Microsoft::WRL::Details::Nil,Microsoft::WRL::Details::Nil,Microsoft::WRL::Details::Nil>,<lambda_fe2b77e5aaa63403fb07ced20bda14ba>,1>::Invoke+0x12
    10eafbe0 0f5e4ac9 0f5e4ab4 10eafc28 77094007 threadpoolwinrt!Windows::System::Threading::CThreadPoolWorkItem::CommonWorkCallback+0x8d
    10eafbec 77094007 10eafc6c 13a40770 144cd110 threadpoolwinrt!Windows::System::Threading::CThreadPoolWorkItem::BatchedCallback+0x15
    10eafc28 770917f1 10eafc6c 144cd170 b87e73ce ntdll!TppWorkpExecuteCallback+0x137
    10eafdc0 74f3919f 094141e8 10eafe14 770cb85f ntdll!TppWorkerThread+0x48e
    10eafdcc 770cb85f 094141e8 b87e701a 00000000 kernel32!BaseThreadInitThunk+0xe
    10eafe14 770cb82a ffffffff 770b072d 00000000 ntdll!__RtlUserThreadStart+0x2f
    10eafe24 00000000 77084e70 094141e8 00000000 ntdll!_RtlUserThreadStart+0x1b


    SYMBOL_STACK_INDEX:  0

    SYMBOL_NAME:  windows_media_speechsynthesis!Microsoft::WRL::Details::RuntimeClass<Microsoft::WRL::Details::InterfaceList<Windows::Foundation::IAsyncOperation<Windows::Media::SpeechSynthesis::SpeechSynthesisStream *>,Microsoft::WRL::Details::InterfaceList<Microsoft::WRL::Cl+11

    FOLLOWUP_NAME:  MachineOwner

    MODULE_NAME: Windows_Media_SpeechSynthesis

    IMAGE_NAME:  Windows.Media.SpeechSynthesis.dll

    DEBUG_FLR_IMAGE_TIMESTAMP:  521574c9

    STACK_COMMAND:  ~30s; .ecxr ; kb

    BUCKET_ID:  APPLICATION_FAULT_WRONG_SYMBOLS_windows_media_speechsynthesis!Microsoft::WRL::Details::RuntimeClass_Microsoft::WRL::Details::InterfaceList_Windows::Foundation::IAsyncOperation_Windows::Media::SpeechSynthesis::SpeechSynthesisStream_*_,Microsoft::WRL::Details::

    FAILURE_BUCKET_ID:  WRONG_SYMBOLS_c0000005_Windows.Media.SpeechSynthesis.dll!Microsoft::WRL::Details::RuntimeClass_Microsoft::WRL::Details::InterfaceList_Windows::Foundation::IAsyncOperation_Windows::Media::SpeechSynthesis::SpeechSynthesisStream_*_,Microsoft::WRL::Details::InterfaceList_Microsoft::WRL::Cl

    ANALYSIS_SOURCE:  UM

    FAILURE_ID_HASH_STRING:  um:wrong_symbols_c0000005_windows.media.speechsynthesis.dll!microsoft::wrl::details::runtimeclass_microsoft::wrl::details::interfacelist_windows::foundation::iasyncoperation_windows::media::speechsynthesis::speechsynthesisstream_*_,microsoft::wrl::details::interfacelist_microsoft::wrl::cl

    FAILURE_ID_HASH:  {9b388dfb-a1bf-a5b4-7d06-311bd4950922}

    Followup: MachineOwner
    ---------
    I've switched my application to cache the generated speech to reduce the number of times I have to generate the speech but the tradeoff is increased save times (especially since I have to transcode to mp3 from wav to save space ) and reduced functionality due to the disk space I now use and not allowing some options that would double or triple the amount of data I save.  Given that these are A/Vs I cannot do anything from my app to protect it any further.  Does anyone have any further suggestions on mitigating this or perhaps have information on an upcoming fix? 

    Thanks

    Rob

    Sunday, January 11, 2015 7:35 AM

Answers

  • Hi Rhouser,

    I can reproduce your issue using the following code snippet.

    public sealed partial class MainPage : Page
    
        {
    
            private MediaElement m_audioPlayer;
    
    
    
            private SpeechSynthesizer m_textToSpeech;
    
    
    
            public SpeechSynthesisStream m_stream
    
            {
    
                get;
    
                set;
    
            }
    
    
            public MainPage()
    
            {
    
                this.InitializeComponent();
    
    
                m_button.Click += m_button_Click;
    
    
                m_audioPlayer = new MediaElement();
    
                m_audioPlayer.AutoPlay = true;
    
                m_grid.Children.Add(m_audioPlayer);
    
    
                m_textToSpeech = new SpeechSynthesizer();
    
            }
    
    
            async void m_button_Click(object sender, RoutedEventArgs e)
    
            {
    
                var timer = new DispatcherTimer();
    
    
                timer.Interval = new TimeSpan(100);
    
    
                timer.Tick += async(s, obj) => {
    
                    m_audioPlayer.Stop();
    
    
                    if (m_stream != null)
    
                    {
    
                        m_stream.Dispose();
    
                        m_stream = null;
    
                    }
    
    
                    string ssml = "<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en\"><voice gender=\"female\" xml:lang=\"en\"><prosody rate=\"1\">how are you doing</prosody><mark name=\"utteranceComplete\"/></voice></speak>";
    
                    m_stream = await m_textToSpeech.SynthesizeSsmlToStreamAsync(ssml);
    
                    m_audioPlayer.SetSource(m_stream, m_stream.ContentType);
    
                };
    
    
                timer.Start();
    
            }
    
        }

    By my research, I found it was caused by the memory access, I assume that the code was accessing the memory which has been released by GC. Please try the following work around and let me know the result.

    public sealed partial class MainPage : Page
        {
            private MediaElement m_audioPlayer;
    
            public MainPage()
            {
                this.InitializeComponent();
    
                m_button.Click += m_button_Click;
    
                m_audioPlayer = new MediaElement();
                m_audioPlayer.AutoPlay = true;
                m_grid.Children.Add(m_audioPlayer);
            }
    
            async void m_button_Click(object sender, RoutedEventArgs e)
            {
                var timer = new DispatcherTimer();
    
                timer.Interval = new TimeSpan(100);
    
                timer.Tick += async (s, obj) =>
                {
                    m_audioPlayer.Stop();
    
                    SpeechSynthesizer textToSpeech = new SpeechSynthesizer();
    
                    string ssml = "<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en\"><voice gender=\"female\" xml:lang=\"en\"><prosody rate=\"1\">how are you doing</prosody><mark name=\"utteranceComplete\"/></voice></speak>";
    
                    SpeechSynthesisStream stream = await textToSpeech.SynthesizeSsmlToStreamAsync(ssml);
    
                    m_audioPlayer.SetSource(stream, stream.ContentType);
                };
    
                timer.Start();
            }
        }
    

    Regards,




    Tuesday, January 13, 2015 2:34 AM
    Moderator