同一输出文件中的AWS 2声音新闻标题和新闻内容

问题描述

我有一条新闻帖子:

新闻帖子的标题(使用语音Joey):

F1 cancels Hanoi 2020 schedule

新闻内容(使用语音:琼)

Turkey,Bahrain (hosting two races),and Abu Dhabi will be part of the revised season,bringing the total number of races to 17,Formula One stated Tuesday. A number of races in the revised 2020 season will be open to a limited number of fans,including hospitality,it said. While three races will be hosted in Asia this year,the Vietnamese Grand Prix in Hanoi did not make the list,along with the Chinese Grand Prix in Shanghai,due to the ongoing Covid-19 pandemic. The Turkish Grand Prix will occur on November 15,before the back-to-back races in Bahrain on November 29 and December 6.

(摘自来源:https://e.vnexpress.net/news/sports/f1-cancels-hanoi-2020-schedule-4152653.html

我尝试过使用NAudio,但是合并后出现音频错误。我正在寻找使用AWS Polly API的本机方式,而不是通过NAudio文件流进行组合。

[HttpGet]
[Route("generate/audio/compound/{id}")]       
public static void GenerateSoundOfNewsCompound(int id)
{
    if (System.IO.File.Exists(@"c:\audio\compound\" + id + ".mp3"))
    {
        // Console.WriteLine("The file exists.");
    }
    else
    {
        // title.
        AmazonPollyClient amazonPollyClient = new AmazonPollyClient("AKIA4NK3K6JXXZ724452","D4rqgC7Ap2H9msff5mO3lxiS1SvXJf6dcpogHnjN",Amazon.RegionEndpoint.EUWest1);
        SynthesizeSpeechRequest synthesizeSpeechRequest = new SynthesizeSpeechRequest();
        synthesizeSpeechRequest.Text = GetNewsTitleById(id);
        // Giọng nam,Anh Mỹ.
        synthesizeSpeechRequest.VoiceId = VoiceId.Joey;
        synthesizeSpeechRequest.OutputFormat = OutputFormat.Mp3;
        synthesizeSpeechRequest.SampleRate = "8000";
        synthesizeSpeechRequest.TextType = "text";
        var response = amazonPollyClient.SynthesizeSpeechAsync(synthesizeSpeechRequest).GetAwaiter().GetResult();
        using (FileStream output = System.IO.File.OpenWrite(@"c:\audio\title\" + id + ".mp3"))
        {
            response.AudioStream.copyTo(output);
        }
        // content.
        SynthesizeSpeechRequest synthesizeSpeechRequest2 = new SynthesizeSpeechRequest();
        synthesizeSpeechRequest2.Text = GetSummary4SentencesById(id);
        // Giọng nữ,Mỹ.
        synthesizeSpeechRequest2.VoiceId = VoiceId.Joanna;
        synthesizeSpeechRequest2.OutputFormat = OutputFormat.Mp3;
        synthesizeSpeechRequest2.SampleRate = "8000";
        synthesizeSpeechRequest2.TextType = "text";                
        var response2 = amazonPollyClient.SynthesizeSpeechAsync(synthesizeSpeechRequest2).GetAwaiter().GetResult();
        using FileStream output2 = System.IO.File.OpenWrite(@"c:\audio\content\" + id + ".mp3");
        response.AudioStream.copyTo(output2);

        // Ghép 2 file.
        string[] foo = { @"c:\audio\title\" + id + ".mp3",@"c:\audio\content\" + id + ".mp3" };
        Stream output3 = System.IO.File.OpenWrite(@"c:\audio\compound\" + id + ".mp3"); ;
        Combine(foo,output3);
    }            
}

// Sinh file (đã bao gồm kiểm tra tồn tại),trả về file.
[HttpGet]
[Route("audio/compound/{id}")]
public IActionResult GetSoundOfNewsPost22(int id)
{
    GenerateSoundOfNewsCompound(id);
    return new PhysicalFileResult(@"c:\audio\compound\" + id + ".mp3","audio/mpeg");
}

如何生成乔伊(Joey)读过的标题和琼(Joan)读过的内容相结合的mp3音频文件

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)