コード例 #1
0
        public override object Clone()
        {
            AzureVoice voice = new AzureVoice(voiceType, locale, Voice);

            voice.Rank = Rank;
            return(voice);
        }
コード例 #2
0
        public static void SpeakString(string textToSpeak, AzureVoice voice)
        {
            SpeakStringAsync(textToSpeak, voice);
            string dirPath  = Path.GetTempPath() + AudioService.TempFolderName;
            string filePath = dirPath + "\\" +
                              string.Format(ELearningLabText.AudioPreviewFileNameFormat, voice.VoiceName);

            PlaySavedAudioForPreview(filePath);
        }
コード例 #3
0
        public void TestClone()
        {
            AzureVoice voice_expected = new AzureVoice(Gender.Female, Locale.enUS, AzureVoiceType.JessaRUS);
            AzureVoice voice_actual   = azureVoice.Clone() as AzureVoice;

            Assert.AreEqual(voice_expected.Rank, voice_actual.Rank);
            Assert.AreEqual(voice_expected.voiceType, voice_actual.voiceType);
            Assert.AreEqual(voice_expected.locale, voice_actual.locale);
            Assert.AreEqual(voice_expected.voiceName, voice_actual.voiceName);
            Assert.AreEqual(voice_expected.VoiceName, voice_actual.VoiceName);
        }
コード例 #4
0
        public static void SpeakStringAsync(string textToSpeak, AzureVoice voice)
        {
            RenewCancellationToken();
            string accessToken;
            string dirPath  = Path.GetTempPath() + AudioService.TempFolderName;
            string filePath = dirPath + "\\" +
                              string.Format(ELearningLabText.AudioPreviewFileNameFormat, voice.VoiceName);

            try
            {
                AzureAccountAuthentication auth = AzureAccountAuthentication.GetInstance();
                accessToken = auth.GetAccessToken();
                Logger.Log("Token: " + accessToken);
            }
            catch
            {
                Logger.Log("Failed authentication.");
                return;
            }
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }
            string requestUri = AzureAccount.GetInstance().GetUri();

            if (requestUri == null)
            {
                return;
            }
            var azureVoiceSynthesizer = new SynthesizeAzureVoice();

            azureVoiceSynthesizer.OnAudioAvailable += PlayAudio;
            azureVoiceSynthesizer.OnError          += OnAzureVoiceErrorHandler;
            // Reuse Synthesize object to minimize latency
            azureVoiceSynthesizer.Speak(token, new InputOptions()
            {
                RequestUri = new Uri(requestUri),
                Text       = textToSpeak,
                VoiceType  = voice.voiceType,
                Locale     = voice.Locale,
                VoiceName  = voice.voiceName,
                // Service can return audio in different output format.
                OutputFormat       = AudioOutputFormat.Riff24Khz16BitMonoPcm,
                AuthorizationToken = "Bearer " + accessToken,
            }, filePath).Wait();
        }
コード例 #5
0
 public void Init()
 {
     azureVoice = new AzureVoice(Gender.Female, Locale.enUS, AzureVoiceType.JessaRUS);
 }
コード例 #6
0
        public static bool SaveStringToWaveFileWithAzureVoice(string textToSave, string filePath, AzureVoice voice)
        {
            RenewCancellationToken();
            string accessToken;
            string textToSpeak = GetHumanSpeakNotesForText(textToSave);

            try
            {
                AzureAccountAuthentication auth = AzureAccountAuthentication.GetInstance();
                accessToken = auth.GetAccessToken();
                Logger.Log("Token: " + accessToken);
            }
            catch
            {
                Logger.Log("Failed authentication.");
                return(false);
            }
            string requestUri = AzureAccount.GetInstance().GetUri();

            if (requestUri == null)
            {
                return(false);
            }
            var azureVoiceSynthesizer = new SynthesizeAzureVoice();

            azureVoiceSynthesizer.OnAudioAvailable += SaveAudioToWaveFile;
            azureVoiceSynthesizer.OnError          += OnAzureVoiceErrorHandler;

            // Reuse Synthesize object to minimize latency
            azureVoiceSynthesizer.Speak(token, new InputOptions()
            {
                RequestUri = new Uri(requestUri),
                Text       = textToSpeak,
                VoiceType  = voice.voiceType,
                Locale     = voice.Locale,
                VoiceName  = voice.voiceName,
                // Service can return audio in different output format.
                OutputFormat       = AudioOutputFormat.Riff24Khz16BitMonoPcm,
                AuthorizationToken = "Bearer " + accessToken,
            }, filePath).Wait();
            return(true);
        }