2014-03-07 38 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(); 
    } 
); 
相關問題