Skip to content

Instantly share code, notes, and snippets.

@buchizo
Created May 24, 2020
Embed
What would you like to do?
neural TTS
using Microsoft.CognitiveServices.Speech;
using System;
using System.Threading.Tasks;
namespace ConsoleApp15
{
class Program
{
private static readonly string ApiKey = "xxxxxxxxxxxxxxxxxxxxxxxx";
static async Task Main(string[] args)
{
Cocona.CoconaApp.Run<Program>(args);
}
public async Task Normal()
{
var config = SpeechConfig.FromSubscription(ApiKey, "eastus");
config.SpeechSynthesisLanguage = "ja-JP";
config.SpeechSynthesisVoiceName = "ja-JP-HarukaRUS";
var speaker = new SpeechSynthesizer(config);
Console.Write("input text: ");
var text = Console.ReadLine();
var result = await speaker.SpeakTextAsync(text);
if (result.Reason == ResultReason.SynthesizingAudioCompleted)
{
Console.WriteLine("end");
}
else if (result.Reason == ResultReason.Canceled)
{
var cancellation = SpeechSynthesisCancellationDetails.FromResult(result);
Console.WriteLine(cancellation.ErrorDetails);
}
}
public async Task Neural()
{
var config = SpeechConfig.FromSubscription(ApiKey, "eastus");
config.SpeechSynthesisLanguage = "ja-JP";
config.SpeechSynthesisVoiceName = "ja-JP-NanamiNeural";
var speaker = new SpeechSynthesizer(config);
Console.Write("input text: ");
var text = Console.ReadLine();
var result = await speaker.SpeakTextAsync(text);
if (result.Reason == ResultReason.SynthesizingAudioCompleted)
{
Console.WriteLine("end");
}
else if (result.Reason == ResultReason.Canceled)
{
var cancellation = SpeechSynthesisCancellationDetails.FromResult(result);
Console.WriteLine(cancellation.ErrorDetails);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment