Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket Connection Closes Unexpectedly When Using SpeakWithText with Text Containing Quotation Marks #355

Open
RazmikGevorgyan opened this issue Dec 4, 2024 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@RazmikGevorgyan
Copy link

RazmikGevorgyan commented Dec 4, 2024

What is the current behavior?

When calling speakClient!.SpeakWithText(text);, the WebSocket connection closes unexpectedly if the text contains quotation marks, such as Did you mean "Male"?.
Reproducible with any special symbols as well such as new line (\n) etc.

Code base to use C# tab of
Deepgram code

Steps to reproduce

  1. Use a C# client to establish a WebSocket connection with speakClient.
  2. Call speakClient!.SpeakWithText(text); with a string containing quotation marks, e.g., Did you mean "Male"?.
  3. Observe that the connection closes unexpectedly.

Expected behavior

The WebSocket connection should remain open, and the text containing quotation marks should be processed without issues.


Please tell us about your environment

  • Operating System/Version: (e.g., Windows 11)
  • .NET Version: (e.g., .NET 8.0)
  • Library Version: (e.g., Deepgram v4.4.0)

Other information

  • Stack trace (if available) or WebSocket close status details:
    • CloseStatus: PolicyViolation
    • CloseStatusDescription: DATA-0000
  • Related areas to investigate: text encoding, escaping special characters, and server-side handling of text input with quotation marks.

@RazmikGevorgyan
Copy link
Author

`// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Speak.v1.WebSocket;

public class TextSource(string text)
{
///


/// Text of the words to speak
///

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("type")]
public string? Type { get; set; } = "Speak";

/// <summary>
/// Text of the words to speak
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("text")]
public string? Text { get; set; } = text;

/// <summary>
/// Override ToString method to serialize the object
/// </summary>
public override string ToString()
{
    return Regex.Unescape(JsonSerializer.Serialize(this));
}

}

`

Here is the fix

@jpvajda jpvajda added the help wanted Extra attention is needed label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants