如何在 SpeechSynthesizer 输出文件的音频中添加暂停?

问题描述 投票:0回答:2

我将相同的文本循环 5 次,但文本重复得太快。我尝试过在字符串之前和之后添加句点,但它不会在每个句子之后添加暂停,例如

// update the status
UpdateStatus("Generating audio");

// create the wav file
ss.Volume = 75;
ss.SelectVoice("VW Julie");

// Generate the Audio file
ss.SetOutputToWaveFile(audio);
int i = 0;
var pronounce = "This is a test sentence"
while (i < 5)
{
    ss.Speak(".................." + pronounce);
    i++;
}

我创建的文件不会在我的 wav 文件中添加暂停,它只是连续的。如何在每个句子之间添加长停顿?

c# text-to-speech
2个回答
0
投票

例如,您可以添加

Thread.Sleep(10000);
,等待几秒钟...

只需添加

using System.Threading;

到您的

using
语句列表并选择适合您的持续时间。

using System.Threading;

{
    ss.Speak(".................." + pronounce);
    i++;
    Thread.Sleep(10000);
}

0
投票

您可以使用speakSsml() 插入暂停,如下所示。

using System;
using System.Speech.Synthesis;

namespace SSMLExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a SpeechSynthesizer object for English speech synthesis
            SpeechSynthesizer synthesizer = new SpeechSynthesizer();

            // Set the SSML text
            string ssmlText = "<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-US\">I am <break time=\"1000ms\"/>a human</speak>";

            try
            {
                // Synthesize speech using SSML
                synthesizer.SpeakSsml(ssmlText);
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred while synthesizing speech: " + ex.Message);
            }

            Console.WriteLine("Speech synthesis completed.");
            Console.ReadLine();
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.