我正在创建一个.net core 3.1应用程序,该应用程序使用文本从天蓝的语音转换为不和谐的语音。但是我遇到的问题是音频流的转换。我正在使用NAudio进行转换,但实际上并没有工作。完美地将mp3转换为不和谐...
我正在使用Discord.net来做。
private async Task SpeakAsync(IAudioClient client, string text)
{
var azureAudio = await new AzureSpeechService().Speak(text);
using var reader = new WaveFileReader(azureAudio);
var nAudio = WaveFormatConversionStream.CreatePcmStream(reader);
Create an empty discord audio stream
AudioStream audioStream = client.CreatePCMStream(AudioApplication.Voice, 32000);
await nAudio.CopyToAsync(audioStream, 50);
await using var discord = client.CreatePCMStream(AudioApplication.Voice);
try { await stream.CopyToAsync(audioStream); }
finally { await discord.FlushAsync(); }
}
天蓝色的流创建代码:
public async Task<Stream> Speak(string text)
{
using var synthesizer = new SpeechSynthesizer(_config, null);
using var result = await synthesizer.SpeakTextAsync(text);
switch (result.Reason)
{
case ResultReason.SynthesizingAudioCompleted:
Console.WriteLine($"Speech synthesized to speaker for text [{text}]");
return new MemoryStream(result.AudioData);
case 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?");
}
return null;
}
default:
return null;
}
}
我试图不使用ffmpeg转换器,所以不需要在服务器上安装其他东西。