I test this service with an asp.net core MVC project
converting text to speech, and got the same situation with you.
The void play automatically after converting locally, but not played on Portal. I check if the .wav
file created or not in Kudu. It shows the file had been created, which means it's not a problem it didn't play, you could download it to listen.
By the way, I use the sample code, just modify the path to store .wav
file:
public async Task SynthesisToSpeakerAsync(string text)
{
// 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("YourSubscriptionKey", "YourServiceRegion");
string path = string.Empty;
string webRootPath = _hostingEnvironment.WebRootPath;
string contentRootPath = _hostingEnvironment.ContentRootPath + "/MyMedia/";
string filename = "sample.wav";
// Try to create the directory.
//DirectoryInfo di = Directory.CreateDirectory(contentRootPath);
// 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("> ");
using (var result = await synthesizer.SpeakTextAsync(text))
{
if (result.Reason == ResultReason.SynthesizingAudioCompleted)
{
Console.WriteLine($"Speech synthesized to speaker for text [{text}]");
var stream = AudioDataStream.FromResult(result);
await stream.SaveToWaveFileAsync(contentRootPath+filename);
Console.WriteLine("Successfully saved");
}
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?");
}
}
}
}
}
Use this api to invoke:
public string test(string txt)
{
SynthesisToSpeakerAsync(txt);
return "";
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…