TTS WP8 Pivot Pages

时间:2014-02-27 15:02:45

标签: c# windows-phone-8 text-to-speech

我正在为我的应用程序设计一个设置页面,我正在使用数据透视页面,我似乎无法弄清楚,一旦用户进入下一个数据透视页面,如何让文本转语音工作。

public partial class Settings : PhoneApplicationPage
{
    IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

    List<Theme1> themesettings = new List<Theme1>();
    List<Theme1> font = new List<Theme1>();
    List<Theme1> fontsize = new List<Theme1>();
    public Settings()
    {
        InitializeComponent();

        themesettings.Add(new Theme1() { ThemeColour = "White", ThemeFontSize = "40" });
        themesettings.Add(new Theme1() { ThemeColour = "Yellow", ThemeFontSize = "40"});
        themesettings.Add(new Theme1() { ThemeColour = "Blue", ThemeFontSize = "40" });
        themesettings.Add(new Theme1() { ThemeColour = "Black", ThemeFontSize = "40" });

        LLsThemeList.ItemsSource = themesettings;

        font.Add(new Theme1() { ThemeText = "White", ThemeFontSize = "40" });
        font.Add(new Theme1() { ThemeText = "Yellow", ThemeFontSize = "40" });
        font.Add(new Theme1() { ThemeText = "Black", ThemeFontSize = "40" });

        LLsFontList.ItemsSource = font;

        fontsize.Add(new Theme1() { ThemeText = "White", ThemeFontSize = "25" });
        fontsize.Add(new Theme1() { ThemeText = "White", ThemeFontSize = "35" });
        fontsize.Add(new Theme1() { ThemeText = "White", ThemeFontSize = "50" });

        LLsTextSizeList.ItemsSource = fontsize;
    }

    private async void SayWords(string words)
    {
        SpeechSynthesizer synth = new SpeechSynthesizer();

        await synth.SpeakTextAsync(words);
    }

    private void ButtonSettings_Click(object sender, RoutedEventArgs e)
    {
        NavigationService.Navigate(new Uri("/Instructions.xaml", UriKind.Relative));
    }

    private void LLsFontList_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        if (LLsFontList != null && LLsFontList.SelectedItem != null)
        {
            var selectedItem = LLsFontList.SelectedItem as Theme1;

            settings["ForeColour"] = selectedItem.ThemeText;

            SayWords("You have chosen Font Colour" + selectedItem.ThemeText + "\r\n");
        }
    }

    private void LLsTextSizeList_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        if (LLsTextSizeList != null && LLsTextSizeList.SelectedItem != null)
        {
            var selectedItem = LLsTextSizeList.SelectedItem as Theme1;
            SayWords("You have chosen Font size " + selectedItem.ThemeFontSize);

            settings["FontSize"] = selectedItem.ThemeFontSize;
        }
    }

    private void LLsThemeList_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        if (LLsThemeList != null && LLsThemeList.SelectedItem != null)
        {
            var selectedItem = LLsThemeList.SelectedItem as Theme1;
            SayWords("You have chosen Theme Colour " + selectedItem.ThemeColour);

            settings["BackColour"] = selectedItem.ThemeColour;
        }
    }

    private void Confirm_Click(object sender, RoutedEventArgs e)
    {
        NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
        settings.Save();
    }
}

这是我的代码到目前为止我可以通过调用用户选择的某些设置来使TTS工作但我似乎无法弄清楚如何让TTS在他们切换到下一个数据透视页时工作。

1 个答案:

答案 0 :(得分:1)

尝试实现Pivot.SelectionChanget事件

的Xaml

<phone:Pivot Title="MY APPLICATION" SelectionChanged="Pivot_SelectionChanged" >        
    <phone:PivotItem Header="first">
    ...
    </phone:PivotItem>        
    <phone:PivotItem Header="second">
    ...
    </phone:PivotItem>
</phone:Pivot>

代码

private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    Pivot pivot = sender as Pivot;
    PivotItem selectedPivotItem = pivot.SelectedItem as PivotItem;
    string pivotName = selectedPivotItem.Header.ToString();
    SayWords(pivotName);
}