2014-03-07 102 views
2

在Windows Phone 8中,我有以下一段使用文本转语音功能的代码。我正在使用带有书签的ssml。但是,当更改Bookmark事件中的任何UI元素(称为函数)时,会引发未授权的异常。System.UnauthorizedAccessException在Windows Phone 8中使用文本转语音功能

private void Initialise_synthesizer() 
     { 
      this.synthesizer = new SpeechSynthesizer(); 

      synthesizer.BookmarkReached += new TypedEventHandler<SpeechSynthesizer, SpeechBookmarkReachedEventArgs> 
       (BookmarkReached); 
     } 

void BookmarkReached(object sender, SpeechBookmarkReachedEventArgs e) 
     { 
      Debugger.Log(1, "Info", e.Bookmark + " mark reached\n"); 

      switch (e.Bookmark) 
      { 
       case "START": 
        cur = start; 
        break; 
       case "LINE_BREAK": 
        cur++; 
        break; 
       } 
**error here** t1.Text = cur.ToString(); 
      } 

但在运行它提供了以下错误

A first chance exception of type 'System.UnauthorizedAccessException' occurred in System.Windows.ni.dll 
An exception of type 'System.UnauthorizedAccessException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary 
Invalid cross-thread access. 

任何想法如何围绕解决这个错误,或任何工作。

回答

2

就得到了答案。已经在

Dispatcher.BeginInvoke(() => 
       t1.Text = cur.ToString()); 
0

从AppManifest.xml开启功能ID_CAP_SPEECH_RECOGNITION。

+1

它 -

由于synthesizer.SpeakSsmlAsync()是一个异步函数,执行UI操作调度员已被使用,这样的事情。 –

1

这几乎与语音识别无关。它似乎与从不同线程访问UI线程中的元素有关。

试试这个:

Dispatcher.BeginInvoke(() => 
    { 
     t1.Text = cur.ToString(); 
    } 
); 
相关问题