首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >将从MP3流中提取的m3u8音频发送到IBM语音到文本

将从MP3流中提取的m3u8音频发送到IBM语音到文本
EN

Stack Overflow用户
提问于 2018-11-14 15:22:32
回答 1查看 317关注 0票数 0

我正在从一个MP3 live中提取M3U8格式的音频,最后的目标是将实时音频流发送到IBM语音到文本。m3u8是通过进程调用外部脚本来获得的。然后我使用FFMPEG脚本在标准输出中获取音频。如果我将音频保存在一个文件中,但我不想保存提取的音频,我需要将数据直接发送到STT服务。到目前为止,我这样做:

代码语言:javascript
代码运行次数:0
运行
复制
SpeechToTextService speechToTextService = new SpeechToTextService(sttUsername, sttPassword);
string m3u8Url = "https://something.m3u8";
char[] buffer = new char[48000];
Process ffmpeg = new ProcessHelper(@"ffmpeg\ffmpeg.exe", $"-v 0 -i {m3u8Url} -acodec mp3 -ac 2 -ar 48000 -f mp3 -");

ffmpeg.Start();
int count;
while ((count = ffmpeg.StandardOutput.Read(buffer, 0, 48000)) > 0)
{
    ffmpeg.StandardOutput.Read(buffer, 0, 48000);
    var answer = speechToTextService.RecognizeSessionless(
        audio: buffer.Select(c => (byte)c).ToArray(),
        contentType: "audio/mpeg",
        smartFormatting: true,
        speakerLabels: false,
        model: "en-US_BroadbandModel"
    );
    // Get answer.ResponseJson, deserializing, clean buffer, etc...
}

当请求转录的音频时,我得到了以下错误:

代码语言:javascript
代码运行次数:0
运行
复制
An unhandled exception of type 'System.AggregateException' occurred in IBM.WatsonDeveloperCloud.SpeechToText.v1.dll: 'One or more errors occurred. (The API query failed with status code BadRequest: Bad Request | x-global-transaction-id: bd6cd203720a70d83b9a03451fe28973 | X-DP-Watson-Tran-ID: bd6cd203720a70d83b9a03451fe28973)'
 Inner exceptions found, see $exception in variables window for more details.
 Innermost exception     IBM.WatsonDeveloperCloud.Http.Exceptions.ServiceResponseException : The API query failed with status code BadRequest: Bad Request | x-global-transaction-id: bd6cd203720a70d83b9a03451fe28973 | X-DP-Watson-Tran-ID: bd6cd203720a70d83b9a03451fe28973
   at IBM.WatsonDeveloperCloud.Http.Filters.ErrorFilter.OnResponse(IResponse response, HttpResponseMessage responseMessage)
   at IBM.WatsonDeveloperCloud.Http.Request.<GetResponse>d__30.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at IBM.WatsonDeveloperCloud.Http.Request.<AsMessage>d__23.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at IBM.WatsonDeveloperCloud.Http.Request.<As>d__24`1.MoveNext()

ProcessHelper只是为了方便起见:

代码语言:javascript
代码运行次数:0
运行
复制
class ProcessHelper : Process
{
    private string command;
    private string arguments;
    public ProcessHelper(string command, string arguments, bool redirectStandardOutput = true)
    {
        this.command = command;
        this.arguments = arguments;
        StartInfo = new ProcessStartInfo()
        {
            FileName = this.command,
            Arguments = this.arguments,
            UseShellExecute = false,
            RedirectStandardOutput = redirectStandardOutput,
            CreateNoWindow = true
        };
    }
}

我肯定我做错了,我希望有人能在这件事上发光。谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-20 14:08:42

我仍然不知道为什么我不能识别我的缓冲区(第二个ffmpeg.StandardOutput.Read(缓冲区,0,48000);是一个错误(顺便说一句),但是我设法使它与websockets一起工作,比如解释https://gist.github.com/nfriedly/0240e862901474a9447a600e5795d500

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53303499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档