Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Runtime.InteropServices.WindowsRuntime;
  6. using Windows.Foundation;
  7. using Windows.Foundation.Collections;
  8. using Windows.Media.SpeechSynthesis;
  9. using Windows.Storage;
  10. using Windows.UI.Xaml;
  11. using Windows.UI.Xaml.Controls;
  12. using Windows.UI.Xaml.Controls.Primitives;
  13. using Windows.UI.Xaml.Data;
  14. using Windows.UI.Xaml.Input;
  15. using Windows.UI.Xaml.Media;
  16. using Windows.UI.Xaml.Navigation;
  17.  
  18. //Szablon elementu Pusta strona jest udokumentowany na stronie https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x415
  19.  
  20. namespace Zadanie7
  21. {
  22.     /// <summary>
  23.     /// Pusta strona, która może być używana samodzielnie lub do której można nawigować wewnątrz ramki.
  24.     /// </summary>
  25.     public sealed partial class MainPage : Page
  26.     {
  27.         public MainPage()
  28.         {
  29.             this.InitializeComponent();
  30.             createFile();
  31.         }
  32.         private async void createFile()
  33.         {
  34.             StorageFolder storageFolder =
  35.             ApplicationData.Current.LocalFolder;
  36.             StorageFile sampleFile =
  37.                 await storageFolder.CreateFileAsync("data.txt",
  38.                     CreationCollisionOption.ReplaceExisting);
  39.  
  40.            
  41.             StorageFile sampleFileToWrite =
  42.                 await storageFolder.GetFileAsync("data.txt");
  43.             await FileIO.WriteTextAsync(sampleFile, "Przykładowy tekst");
  44.         }
  45.         private async void Button_Click_Man(object sender, RoutedEventArgs e)
  46.         {
  47.             var file = await ApplicationData.Current.LocalFolder.GetFileAsync("data.txt");
  48.             var lines = await FileIO.ReadLinesAsync(file);
  49.             MediaElement mediaElement = new MediaElement();
  50.             var syn = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
  51.             VoiceInformation voiceInfo =
  52.         (
  53.             from voice in SpeechSynthesizer.AllVoices
  54.             where voice.Gender == VoiceGender.Male
  55.             select voice
  56.         ).FirstOrDefault() ?? SpeechSynthesizer.DefaultVoice;
  57.             syn.Voice = voiceInfo;
  58.             foreach (string line in lines){
  59.                 Windows.Media.SpeechSynthesis.SpeechSynthesisStream stm =
  60.                 await syn.SynthesizeTextToStreamAsync(line);
  61.                 mediaElement.SetSource(stm, stm.ContentType);
  62.                 mediaElement.Play();
  63.             }
  64.            
  65.            
  66.         }
  67.  
  68.         private async void Button_Click_Woman(object sender, RoutedEventArgs e)
  69.         {
  70.             var file = await ApplicationData.Current.LocalFolder.GetFileAsync("data.txt");
  71.             var lines = await FileIO.ReadLinesAsync(file);
  72.             MediaElement mediaElement = new MediaElement();
  73.             var syn = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
  74.            
  75.             foreach (string line in lines)
  76.             {
  77.                 Windows.Media.SpeechSynthesis.SpeechSynthesisStream stm =
  78.                 await syn.SynthesizeTextToStreamAsync(line);
  79.                
  80.                 mediaElement.SetSource(stm, stm.ContentType);
  81.                 mediaElement.Play();
  82.             }
  83.  
  84.  
  85.         }
  86.  
  87.  
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement