本文介绍了我可以估计合成语音的持续时间吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用用户输入的特定持续时间在 Windows 操作系统中从文本生成波形文件.例如,如果用户希望波形文件的HH:MM:SS"时间跨度(获取格式为 Total secs).. 文本I love Stack Overflow"将循环用于HH:MM:SS".

I am trying the generate wave file in windows OS from Text with specific duration entered by the user. For example If the user wants to "HH:MM:SS" timespan (get the format as Total secs) of wave file .. with the text "I love Stack Overflow" to be looped for "HH:MM:SS".

如何从文本中计算 Wavfile 的持续时间并生成具有特定持续时间的 Wavefile 并将其保存到磁盘.我需要遵循什么算法或代码?

How can I calculate the duration of Wavfile from the text and and generate the Wavefile with the specific duration and save it to the disk. what algorithm or code I need to follow?

目前我正在使用 Speech.Synthesis 生成文本到波形文件,但从文本计算持续时间在这里似乎是个大问题..

Currently I am using Speech.Synthesis to generate text to wavefile but calculating duration from text seems to be big problem here..

推荐答案

跟踪语音生成的进度.SpeakProgressEventArgs 有一个 AudioPosition 属性,它是一个 TimeSpan.时间在 Speak 调用之间重置,因此您可以使用单个 System.Speech.Synthesis.PromptBuilder 来获取整个持续时间,例如,如果您有多个短语、句子、ssml 标记或具有不同重点、音量或速率的区域.

Track progress of speech generation. SpeakProgressEventArgs has a AudioPosition property which is a TimeSpan. Timings are reset between Speak calls so you could use a single System.Speech.Synthesis.PromptBuilder for instance to get the whole duration if you have multiple phrases, sentences, ssml markup or zones with different emphasis, volume or rate.

  SpeechSynthesizer synth = new SpeechSynthesizer();
  synth.SpeakProgress += new EventHandler<SpeakProgressEventArgs>(synth_SpeakProgress);
  //
  string s1 = "I love Stack Overflow";
  PromptBuilder builder = new PromptBuilder();
  builder.AppendSsmlMarkup("I love <emphasis>Stack Overflow</emphasis>");
  builder.AppendText(s1);
  builder.AppendText(s1, PromptEmphasis.Strong);
  builder.AppendText(s1, PromptRate.ExtraFast);
  builder.AppendText(s1,PromptVolume.Loud);
  //
  synth.Speak(builder);

static void synth_SpeakProgress (object sender, SpeakProgressEventArgs e)
{
  Console.WriteLine("Speak progress: {0} AudioPosition: {1} Text: {2}", e.CharacterPosition, e.AudioPosition, e.Text);
}

这篇关于我可以估计合成语音的持续时间吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 14:41