相关疑难解决方法(0)

将视频字幕与文字转语音同步

我尝试创建一个文本视频,其中文本通过文本到语音进行叙述.

要创建的视频文件,我用VideoFileWriterAforge.Net是以下几点:

VideoWriter = new VideoFileWriter();

VideoWriter.Open(CurVideoFile, (int)(Properties.Settings.Default.VideoWidth),
    (int)(Properties.Settings.Default.VideoHeight), 25, VideoCodec.MPEG4, 800000);
Run Code Online (Sandbox Code Playgroud)

要大声朗读文本,我使用SpeechSynthesizer类并将输出写入波流

AudioStream = new FileStream(CurAudioFile, FileMode.Create);
synth.SetOutputToWaveStream(AudioStream);
Run Code Online (Sandbox Code Playgroud)

我想突出显示视频中的单词,所以我通过SpeakProgress事件同步它们:

void synth_SpeakProgress(object sender, SpeakProgressEventArgs e)
{

    curAuidoPosition = e.AudioPosition;
    using (Graphics g = Graphics.FromImage(Screen))
    {
         g.DrawString(e.Text,....); 
    }                    
    VideoWriter.WriteVideoFrame(Screen, curAuidoPosition);
}
Run Code Online (Sandbox Code Playgroud)

最后,我使用合并视频和音频 ffmpeg

using (Process process = new Process())
{
        process.StartInfo.FileName = exe_path;
        process.StartInfo.Arguments = 
            string.Format(@"-i ""{0}"" -i ""{1}"" -y -acodec copy -vcodec copy ""{2}""", avi_path, mp3_path, output_file);

        // ...
}
Run Code Online (Sandbox Code Playgroud)

问题是,对于像微软Hazel,Zira和David这样的声音,在Windows 8.1中,视频与音频不同步,音频比显示的字幕快得多.但是,对于Windows …

c# audio speech-synthesis speechsynthesizer aforge

8
推荐指数
0
解决办法
1048
查看次数

标签 统计

aforge ×1

audio ×1

c# ×1

speech-synthesis ×1

speechsynthesizer ×1