Azure Speech in Foundry Tools
An Azure service that integrates speech processing into apps and services.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Microsoft.CognitiveServices.Speech无法朗读中文
代码如下:
public static async Task SynthesisToSpeakerAsync()
{
// Creates an instance of a speech config with specified subscription key and service region.
// Replace with your own subscription key and service region (e.g., "westus").
// The default language is "en-us".
var config = SpeechConfig.FromSubscription("XXXXXXXXXXXXXXXXXX", "westus2");
// Creates a speech synthesizer using the default speaker as audio output.
using (var synthesizer = new SpeechSynthesizer(config))
{
// Receive a text from console input and synthesize it to speaker.
Console.WriteLine("Type some text that you want to speak...");
Console.Write("> ");
string text = Console.ReadLine();
using (var result = await synthesizer.SpeakTextAsync("这里是朗读的内容,this is aloud content"))
{
if (result.Reason == ResultReason.SynthesizingAudioCompleted)
{
Console.WriteLine($"Speech synthesized to speaker for text [{text}]");
}
else if (result.Reason == ResultReason.Canceled)
{
var cancellation = SpeechSynthesisCancellationDetails.FromResult(result);
Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");
if (cancellation.Reason == CancellationReason.Error)
{
Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
Console.WriteLine($"CANCELED: ErrorDetails=[{cancellation.ErrorDetails}]");
Console.WriteLine($"CANCELED: Did you update the subscription info?");
}
}
}
// This is to give some time for the speaker to finish playing back the audio
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
static async Task Main()
{
await SynthesisToSpeakerAsync();
}
An Azure service that integrates speech processing into apps and services.
Answer accepted by question author
config.SpeechRecognitionLanguage = "zh-CN";
config.SpeechSynthesisLanguage= "zh-CN";
//https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/language-support#neural-voices
config.SpeechSynthesisVoiceName = "zh-CN-XiaoxiaoNeural ";
ok