locked
Sythesizer.SynthesizeTextToStreamAsync throwing UnauthorizedAccessException RRS feed

  • Question

  • I am trying to get the speech synthesizer to read text written in a textbox. When I run the code, I get an exception. Please help me understand why. I am using Visual Studio 2013 Ultimate. Below is the complete code:

    XAML

    <Page
        x:Class="SpeechDemo.MainPage"
        x:Name='page'
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:SpeechDemo"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Grid.RowDefinitions>
                <RowDefinition Height='Auto' />
                <RowDefinition Height='*' />
            </Grid.RowDefinitions>
    
            <StackPanel Orientation='Horizontal'
                        Grid.Row='0'>
                <ComboBox ItemsSource='{Binding Path=Voices, ElementName=page}'
                          Width='300'
                          Margin='10'
                          x:Name='VoiceComboBox'>
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text='{Binding DisplayName}'
                                       FontSize='20' />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
    
                <Button x:Name='SelectVoiceButton'
                        Content='Speak'
                        Click='SelectVoiceButton_Click' />
    
                <MediaElement x:Name='SpeechElement'
                              AudioCategory='ForegroundOnlyMedia'
                              AutoPlay='True' />
            </StackPanel>
            <TextBox x:Name='SpeechTextBox'
                     Grid.Row='1'
                     Margin='10' />
        </Grid>
    </Page>

    C#

    using System;
    using System.Collections.Generic;
    using Windows.Media.SpeechSynthesis;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    
    // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
    
    namespace SpeechDemo
    {
        /// <summary>
        /// An empty page that can be used on its own or navigated to within a Frame.
        /// </summary>
        public sealed partial class MainPage : Page
        {
            public MainPage()
            {
                this.InitializeComponent();
            }
    
            public IReadOnlyList<VoiceInformation> Voices { get { return SpeechSynthesizer.AllVoices; } }
    
            private async void SelectVoiceButton_Click(object sender, RoutedEventArgs e)
            {
                string text = SpeechTextBox.Text.Trim();
    
                SpeechSynthesizer synthesizer = new SpeechSynthesizer();
    
                VoiceInformation voice = VoiceComboBox.SelectedItem as VoiceInformation;
    
                if (voice != null)
                    synthesizer.Voice = voice;
    
                SpeechSynthesisStream stream = await synthesizer.SynthesizeTextToStreamAsync(text);
    
                SpeechElement.SetSource(stream, stream.ContentType);
                
            }
        }
    }

    Exception being thrown:

    An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code

    WinRT information: Access is denied.

    Additional information: Access is denied.

    Access is denied.

    If there is a handler for this exception, the program may be safely continued.


    The best things in life are free, but the most valuable ones are costly...use opportunities well for there are others like you who deserves them, but don't have them...


    • Edited by talk2alie Sunday, January 26, 2014 8:12 PM
    Sunday, January 26, 2014 8:11 PM

All replies