簡體   English   中英

如何將實時音頻 stream 端點連接到直線語音端點?

[英]How to hook real-time audio stream endpoint to Direct Line Speech Endpoint?

我正在嘗試將產生連續音頻 stream 的實時音頻端點與最終與我的 Azure 機器人 Z8A5DA52ED126447D359E70C05721A 交互的直線語音 (DLS) 端點連接起來。

我有一個 websocket API 可以連續接收二進制格式的音頻 stream,這就是我打算將其轉發到 DLS 端點以使用我的機器人連續 Speech2Text 的內容。

根據此處的反饋和回答,我已經能夠將我的 Direct Line 語音端點與實時 stream 連接起來。

我已經嘗試了一個示例 wav 文件,該文件正確地被 DLS 轉錄,並且我的機器人能夠正確地檢索文本以對其進行操作。

我使用了ListenOnce() API並使用PushAudioInputStream方法將音頻 stream 推送到 DLS 語音端點。

下面的代碼是 ListenOnce() 方法的內部代碼

// Create a push stream
using (var pushStream = AudioInputStream.CreatePushStream())
{
    using (var audioInput = AudioConfig.FromStreamInput(pushStream))
    {
        // Create a new Dialog Service Connector
        this.connector = new DialogServiceConnector(dialogServiceConfig, audioInput);
        // ... also subscribe to events for this.connector

        // Open a connection to Direct Line Speech channel
        this.connector.ConnectAsync();
        Debug.WriteLine("Connecting to DLS");

        pushStream.Write(dataBuffer, dataBuffer.Length);

        try
        {
            this.connector.ListenOnceAsync();
            System.Diagnostics.Debug.WriteLine("Started ListenOnceAsync");
        }
    }
}

上面代碼中的 dataBuffer 是我在 websocket 上收到的二進制數據的“塊”。

const int maxMessageSize = 1024 * 4; // 4 bytes
var dataBuffer = new byte[maxMessageSize];

while (webSocket.State == WebSocketState.Open)
{
    var result = await webSocket.ReceiveAsync(new ArraySegment<byte>(dataBuffer), CancellationToken.None);
    if (result.MessageType == WebSocketMessageType.Close)
    {
        Trace.WriteLine($"Received websocket close message: {result.CloseStatus.Value}, {result.CloseStatusDescription}");
        await webSocket.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None);
    }
    else if (result.MessageType == WebSocketMessageType.Text)
    {
        var message = Encoding.UTF8.GetString(dataBuffer);
        Trace.WriteLine($"Received websocket text message: {message}");
    }
    else // binary
    {
        Trace.WriteLine("Received websocket binary message");
        ListenOnce(dataBuffer); //calls the above 
    }
}

但是上面的代碼不起作用。 我相信我對這種方法有幾個問題/疑問 -

  1. 我相信我沒有正確地將數據分塊到 Direct Line Speech 以確保它接收完整的音頻以進行正確的 S2T 轉換。
  2. 我知道 DLS API 支持ListenOnceAsync()但不確定這是否支持 ASR(它知道另一邊的揚聲器何時停止說話)
  3. Can I just get the websocket url for the Direct Line Speech endpoint and assume DLS correctly consumes the direct websocket stream?

我相信我沒有正確地將數據分塊到 Direct Line Speech 以確保它接收完整的音頻以進行正確的 S2T 轉換。

DialogServiceConnector.ListenOnceAsync將一直監聽到 stream 關閉(或檢測到足夠的靜音) 您不會關閉 stream ,除非您在 using 塊結束時將其丟棄。 您可以等待ListenOnceAsync ,但您必須確保先關閉 stream。 If you don't await ListenOnceAsync then you can close the stream whenever you want, but you should probably do it as soon as you finish writing to the stream and you have to make sure you don't dispose of the stream (or the config ) 在ListenOnceAsync有機會完成之前。

您還想確保ListenOnceAsync獲得完整的話語。 如果您一次只接收 4 個字節,那么這肯定不是完整的話語。 如果您想將塊保持在 4 個字節,那么在該循環的多次迭代期間保持ListenOnceAsync運行可能是一個好主意,而不是每獲得 4 個字節就一遍又一遍地調用它。

我知道 DLS API 支持 ListenOnceAsync() 但不確定這是否支持 ASR(它知道另一邊的揚聲器何時停止說話)

我認為您必須確定揚聲器何時停止在客戶端說話,然后從您的 WebSocket 收到一條消息,指示您應該關閉音頻 stream 的ListenOnceAsync

看起來ListenOnceAsync確實支持 ASR。

Can I just get the websocket url for the Direct Line Speech endpoint and assume DLS correctly consumes the direct websocket stream?

你可以試試,但我自己不會這么認為。 Direct Line Speech 仍處於預覽階段,我不希望兼容性變得容易。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM