Отправка аудио в формате MP3, извлеченного из потока m3u8, в IBM Watson Speech To Text - PullRequest
0 голосов
/ 14 ноября 2018

Я извлекаю аудио в формате MP3 из URL-адреса в реальном времени M3U8, и конечной целью является отправка потокового аудио в IBM Watson Speech To Text. M3u8 получается путем вызова внешнего скрипта через процесс. Затем я использую скрипт FFMPEG, чтобы получить звук в стандартный вывод. Это работает, если я сохраняю аудио в файл, но не хочу сохранять извлеченное аудио, мне нужно отправить данные напрямую в службу STT. Пока я действовал так:

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...
}

При запросе транскрибированного аудио я получаю эту ошибку:

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 просто для удобства:

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
        };
    }
}

Уверен, что я делаю это неправильно, я бы хотел, чтобы кто-то пролил свет на это. Благодаря.

1 Ответ

0 голосов
/ 20 ноября 2018

Я до сих пор не знаю, почему я не могу распознать мой буфер без сессии (второй ffmpeg.StandardOutput.Read (buffer, 0, 48000); кстати, был опечаткой), но мне удалось заставить его работать с веб-сокетами, как объяснено тамhttps://gist.github.com/nfriedly/0240e862901474a9447a600e5795d500

...