Advertisement
Guest User

Untitled

a guest
Jul 16th, 2011
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using System.Speech.Synthesis;
  7.  
  8. namespace Glossolalia
  9. {
  10.     class Program
  11.     {
  12.         static string BuildString()
  13.         {
  14.             string consonants = "cdfghllllllmmmnnnpssswwwy";
  15.             string vowels = "aaaaeeeioou";
  16.  
  17.             List<string> sounds = new List<string>();
  18.  
  19.             foreach (char vowel in vowels)
  20.             {
  21.                 foreach (char consonant in consonants)
  22.                 {
  23.                     sounds.Add(vowel.ToString() + consonant.ToString());
  24.                 }
  25.             }
  26.  
  27.             Random random = new Random();
  28.  
  29.             string result = "";
  30.  
  31.             int repeatChance = 3;
  32.  
  33.             for (int i = 0; i < random.Next(200, 500); i++)
  34.             {
  35.                 string syllable = sounds[random.Next(0, sounds.Count)];
  36.  
  37.                 result += syllable;
  38.  
  39.                 // Random repetition
  40.                 if (random.Next(0, repeatChance) == 0)
  41.                 {
  42.                     result += syllable;
  43.                     repeatChance++;
  44.                 }
  45.  
  46.                 if (!result.EndsWith(" ") &&
  47.                     !result.EndsWith(",") &&
  48.                     !result.EndsWith("."))
  49.                 {
  50.                     // Random space
  51.                     if (random.Next(0, 3) == 0)
  52.                     {
  53.                         result += " ";
  54.                         repeatChance = 3;
  55.                     }
  56.                     // Random comma
  57.                     else if (random.Next(0, 10) == 0)
  58.                     {
  59.                         result += ", ";
  60.                         repeatChance = 3;
  61.                     }
  62.                     // Random full stop
  63.                     else if (random.Next(0, 20) == 0)
  64.                     {
  65.                         result += ". ";
  66.                         repeatChance = 3;
  67.                     }
  68.                 }
  69.             }
  70.  
  71.             return result + sounds[random.Next(0, sounds.Count)] + ".";
  72.         }
  73.  
  74.         static void Main(string[] args)
  75.         {
  76.             SpeechSynthesizer synthesizer = new SpeechSynthesizer();
  77.  
  78.             string say = BuildString();
  79.             Console.Write(say);
  80.  
  81.             synthesizer.Speak(say);
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement