Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices.WindowsRuntime;
- using Windows.Foundation;
- using Windows.Foundation.Collections;
- using Windows.Media.SpeechSynthesis;
- using Windows.Storage;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- using Windows.UI.Xaml.Controls.Primitives;
- using Windows.UI.Xaml.Data;
- using Windows.UI.Xaml.Input;
- using Windows.UI.Xaml.Media;
- using Windows.UI.Xaml.Navigation;
- //Szablon elementu Pusta strona jest udokumentowany na stronie https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x415
- namespace Zadanie7
- {
- /// <summary>
- /// Pusta strona, która może być używana samodzielnie lub do której można nawigować wewnątrz ramki.
- /// </summary>
- public sealed partial class MainPage : Page
- {
- public MainPage()
- {
- this.InitializeComponent();
- createFile();
- }
- private async void createFile()
- {
- StorageFolder storageFolder =
- ApplicationData.Current.LocalFolder;
- StorageFile sampleFile =
- await storageFolder.CreateFileAsync("data.txt",
- CreationCollisionOption.ReplaceExisting);
- StorageFile sampleFileToWrite =
- await storageFolder.GetFileAsync("data.txt");
- await FileIO.WriteTextAsync(sampleFile, "Przykładowy tekst");
- }
- private async void Button_Click_Man(object sender, RoutedEventArgs e)
- {
- var file = await ApplicationData.Current.LocalFolder.GetFileAsync("data.txt");
- var lines = await FileIO.ReadLinesAsync(file);
- MediaElement mediaElement = new MediaElement();
- var syn = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
- VoiceInformation voiceInfo =
- (
- from voice in SpeechSynthesizer.AllVoices
- where voice.Gender == VoiceGender.Male
- select voice
- ).FirstOrDefault() ?? SpeechSynthesizer.DefaultVoice;
- syn.Voice = voiceInfo;
- foreach (string line in lines){
- Windows.Media.SpeechSynthesis.SpeechSynthesisStream stm =
- await syn.SynthesizeTextToStreamAsync(line);
- mediaElement.SetSource(stm, stm.ContentType);
- mediaElement.Play();
- }
- }
- private async void Button_Click_Woman(object sender, RoutedEventArgs e)
- {
- var file = await ApplicationData.Current.LocalFolder.GetFileAsync("data.txt");
- var lines = await FileIO.ReadLinesAsync(file);
- MediaElement mediaElement = new MediaElement();
- var syn = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
- foreach (string line in lines)
- {
- Windows.Media.SpeechSynthesis.SpeechSynthesisStream stm =
- await syn.SynthesizeTextToStreamAsync(line);
- mediaElement.SetSource(stm, stm.ContentType);
- mediaElement.Play();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement