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

Support named entities in the JSON response #10

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions SmRtAPI/SmRtAPI/Messages/WordSubMessage.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Newtonsoft.Json;

namespace Speechmatics.Realtime.Client.Messages
{
/// <summary>
Expand All @@ -6,7 +8,7 @@ namespace Speechmatics.Realtime.Client.Messages
public class WordSubMessage : BaseMessage
{
/// <summary>
/// Type for this token, one of "word", "punctuation" or "speaker_change"
/// Type for this token, one of "word", "punctuation" or "entity"
/// </summary>
public string type;
/// <summary>
Expand All @@ -17,20 +19,56 @@ public class WordSubMessage : BaseMessage
/// End time
/// </summary>
public double end_time;

/// <summary>
/// Whether the element represents an end of sentence marker (e.g. full stop, question mark, exclamation mark)
/// </summary>
public bool is_eos;

/// <summary>
/// Whether this punctuation mark attaches to previous or next token.
/// </summary>
public string? attaches_to;
/// <summary>
/// Audio length (seconds)
/// Alternative options for the words (currently of length 1)
/// </summary>
public Alternative[] alternatives;
/// <summary>
/// If the word is a named entity, the class of the entity (money, date, etc), otherwise omitted
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string? entity_class;
/// <summary>
/// For an entity, the recognized spoken words, otherwise omitted
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public EntitySpokenOrWrittenForm[]? spoken_form;
/// <summary>
/// For an entity, the written form of the recognised words, otherwise omitted
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public EntitySpokenOrWrittenForm[]? written_form;
}

/// <summary>
/// Represents the spoken or written form of an entity (money, date, etc)
/// </summary>
public class EntitySpokenOrWrittenForm
{
/// <summary>
/// Alternative options for the words (currently of length 1)
/// </summary>
public Alternative[] alternatives;
/// <summary>
/// Type for this token (usually 'word' when dealing with entity sub-components)
/// </summary>
public string type;
/// <summary>
/// Start time (offset from audio start) of the whole entity
/// </summary>
public double start_time;
/// <summary>
/// End time of the whole entity
/// </summary>
public double end_time;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion SmRtAPI/Speechmatics.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Speechmatics</id>
<version>1.1.1</version>
<version>1.1.3</version>
<authors>Speechmatics</authors>
<owners>Speechmatics</owners>
<readme>docs/README.md</readme>
Expand Down