【问题标题】:Microsoft TTS SaveToWaveFileAsync function not workingMicrosoft TTS SaveToWaveFileAsync 功能不起作用
【发布时间】:2021-04-28 21:14:58
【问题描述】:

我正在使用 Xamarin Forms 开发移动文本到语音应用程序。 Quickstart 到目前为止工作并合成了我的文本,但将结​​果保存到文件似乎不起作用。这是合成类的代码:

        var config = SpeechConfig.FromSubscription("6e4a67f034a545e0833179044dd6d172", "westeurope");
        var synthesizer = new SpeechSynthesizer(config);
        var result = await synthesizer.SpeakSsmlAsync(xmlFirstPart + voice + xmlSecondPart + synthesisText + xmlThirdPart).ConfigureAwait(false);
        var stream = AudioDataStream.FromResult(result);
      
        string file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "SpeechSynthesis.wav");
        await stream.SaveToWaveFileAsync(file);

它没有给出错误,但是一旦我用这个代码从另一个类调用它:

ISimpleAudioPlayer player = CrossSimpleAudioPlayer.CreateSimpleAudioPlayer();
player.Load(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "SpeechSynthesis.wav"));

它给出了以下错误:

Java.IO.FileNotFoundException: '/data/user/0/com.companyname.mobileapp/files/SpeechSynthesis.wav'

如果有人知道可能导致此错误的原因,那将对我有很大帮助。谢谢。

【问题讨论】:

标签: c# azure xamarin xamarin.forms text-to-speech


【解决方案1】:

用法看起来不错,但您使用的路径似乎错误:Environment.GetFolderPath(Environment.SpecialFolder.Personal), "SpeechSynthesis.wav"

例如,尝试给"path/to/write/file.wav",它会起作用。

或者,您可以使用以下代码保存到 .wav:

using var audioConfig = AudioConfig.FromWavFileOutput("path/to/write/file.wav");

【讨论】:

  • 遗憾的是,这并不能解决问题——同样的错误仍然存​​在。我用 File.exists 测试了文件路径。它返回 true,但每当我尝试使用 player.Load 函数时,它都会说不存在这样的文件。我很困惑,因为这两者相互矛盾。
  • 你能试试这里解释的代码吗?:codexamarin.blogspot.com/2019/01/…
  • 另外,您在player.Load 中提供了哪条路径?和SaveToWaveFileAsync的路径一样吗?
  • 我使用的是相同的路径。 Player.Load 不返回错误,而只是冻结。
  • 是的。有用。但是 wav 文件必须在资源文件夹中。我要播放的文件是在运行时创建的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-11
  • 2021-03-10
  • 1970-01-01
  • 1970-01-01
  • 2023-03-13
相关资源
最近更新 更多