Ejemplo n.º 1
0
        public static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += Application_ThreadException;

            // credentials
            var userProfile = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
            var projectsDir = userProfile.CD("Projects");
            var keyFile     = projectsDir.CD("DevKeys").Touch("azure-speech.txt");
            var lines       = File.ReadAllLines(keyFile.FullName);

            client = new TextToSpeechClient(
                lines[0],
                lines[1],
                lines[2],
                new JsonFactory <Voice[]>(),
                new NAudioAudioDataDecoder(),
                new CachingStrategy
            {
                new FileCacheLayer(projectsDir)
            });

            using var p = player = new SoundPlayer();
            using var f = form = new SpeechGen();
            form.SetVoices(client.GetVoicesAsync().Result);

            form.GenerateSpeech += Form_GenerateSpeech;

            Application.Run(form);
        }
Ejemplo n.º 2
0
        public static async Task Main(string[] args)
        {
            var text = "The quick brown fox jumps over the lazy dog.";

            if (args?.Length > 1)
            {
                text = args[1];
            }

            // credentials
            var userProfile     = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            var keyFile         = Path.Combine(userProfile, "Projects", "DevKeys", "azure-speech.txt");
            var lines           = File.ReadAllLines(keyFile);
            var subscriptionKey = lines[0];
            var region          = lines[1];
            var resourceName    = lines[2];

            // caching
            var cacheDirName = Path.Combine(userProfile, "Projects");
            var cacheDir     = new DirectoryInfo(cacheDirName);
            var cache        = new CachingStrategy
            {
                new FileCacheLayer(cacheDir)
            };

            var voiceListDecoder = new JsonFactory <Voice[]>();

            var audioDecoder = new NAudioAudioDataDecoder();

            var ttsClient = new TextToSpeechClient(
                region,
                subscriptionKey,
                resourceName,
                voiceListDecoder,
                audioDecoder,
                cache);

            var voices = await ttsClient
                         .GetVoicesAsync()
                         .ConfigureAwait(false);

            var voice = Array.Find(voices, v => v.Locale == "en-US" && v.Gender == "Female");

            try
            {
                //await DecodeAudio(text, audioDecoder, ttsClient, voice);
                await PlayAudioAsync(text, audioDecoder, ttsClient, voice).ConfigureAwait(false);

                Console.WriteLine("Success!");
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
            }
        }