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

Add SegmentationSilenceTimeoutMs property #509

Merged
Merged
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
54 changes: 14 additions & 40 deletions src/common.speech/ConnectionFactoryBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,47 +33,21 @@ export abstract class ConnectionFactoryBase implements IConnectionFactory {
queryParams: IStringDictionary<string>,
endpoint: string): void {

this.setUrlParameter(PropertyId.SpeechServiceConnection_EnableAudioLogging,
QueryParameterNames.EnableAudioLogging,
config,
queryParams,
endpoint);

this.setUrlParameter(PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps,
QueryParameterNames.EnableWordLevelTimestamps,
config,
queryParams,
endpoint);

this.setUrlParameter(PropertyId.SpeechServiceResponse_ProfanityOption,
QueryParameterNames.Profanity,
config,
queryParams,
endpoint);

this.setUrlParameter(PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs,
QueryParameterNames.InitialSilenceTimeoutMs,
config,
queryParams,
endpoint);

this.setUrlParameter(PropertyId.SpeechServiceConnection_EndSilenceTimeoutMs,
QueryParameterNames.EndSilenceTimeoutMs,
config,
queryParams,
endpoint);

this.setUrlParameter(PropertyId.SpeechServiceResponse_StablePartialResultThreshold,
QueryParameterNames.StableIntermediateThreshold,
config,
queryParams,
endpoint);
const propertyIdToParameterMap: Map<number, string> = new Map([
[PropertyId.Speech_SegmentationSilenceTimeoutMs, QueryParameterNames.SegmentationSilenceTimeoutMs],
[PropertyId.SpeechServiceConnection_EnableAudioLogging, QueryParameterNames.EnableAudioLogging],
[PropertyId.SpeechServiceConnection_EndSilenceTimeoutMs, QueryParameterNames.EndSilenceTimeoutMs],
[PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs, QueryParameterNames.InitialSilenceTimeoutMs],
[PropertyId.SpeechServiceResponse_PostProcessingOption, QueryParameterNames.Postprocessing],
[PropertyId.SpeechServiceResponse_ProfanityOption, QueryParameterNames.Profanity],
[PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps, QueryParameterNames.EnableWordLevelTimestamps],
[PropertyId.SpeechServiceResponse_StablePartialResultThreshold, QueryParameterNames.StableIntermediateThreshold],
]);

propertyIdToParameterMap.forEach((parameterName: string, propertyId: PropertyId): void => {
this.setUrlParameter(propertyId, parameterName, config, queryParams, endpoint);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for simplifying this!


this.setUrlParameter(PropertyId.SpeechServiceResponse_PostProcessingOption,
QueryParameterNames.Postprocessing,
config,
queryParams,
endpoint);

const serviceProperties: IStringDictionary<string> = JSON.parse(config.parameters.getProperty(ServicePropertiesPropertyName, "{}")) as IStringDictionary<string>;

Expand Down
1 change: 1 addition & 0 deletions src/common.speech/QueryParameterNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class QueryParameterNames {
public static EnableLanguageId: string = "lidEnabled";
public static EnableWordLevelTimestamps: string = "wordLevelTimestamps";
public static EndSilenceTimeoutMs: string = "endSilenceTimeoutMs";
public static SegmentationSilenceTimeoutMs: string = "segmentationSilenceTimeoutMs";
public static Format: string = "format";
public static InitialSilenceTimeoutMs: string = "initialSilenceTimeoutMs";
public static Language: string = "language";
Expand Down
15 changes: 15 additions & 0 deletions src/sdk/PropertyId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@ export enum PropertyId {
*/
SpeechServiceConnection_EndSilenceTimeoutMs,

/**
* A duration of detected silence, measured in milliseconds, after which speech-to-text will determine a spoken
* phrase has ended and generate a final Recognized result. Configuring this timeout may be helpful in situations
* where spoken input is significantly faster or slower than usual and default segmentation behavior consistently
* yields results that are too long or too short. Segmentation timeout values that are inappropriately high or low
* can negatively affect speech-to-text accuracy; this property should be carefully configured and the resulting
* behavior should be thoroughly validated as intended.
*
* For more information about timeout configuration that includes discussion of default behaviors, please visit
* https://aka.ms/csspeech/timeouts.
*
* Added in version 1.21.0.
*/
Speech_SegmentationSilenceTimeoutMs,

/**
* A boolean value specifying whether audio logging is enabled in the service or not.
* Added in version 1.7.0
Expand Down
17 changes: 17 additions & 0 deletions tests/SpeechConfigTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,23 @@ describe("Connection URL Tests", () => {
);
});

test("segmentationSilenceTimeoutMs", (done: jest.DoneCallback) => {
// tslint:disable-next-line:no-console
console.info("Name: segmentationSilenceTimeoutMs");

const propName: string = "segmentationSilenceTimeoutMs";
const val: string = "452";

testUrlParameter(createMethod,
(s: sdk.SpeechConfig): void => {
s.setProperty(sdk.PropertyId[sdk.PropertyId.Speech_SegmentationSilenceTimeoutMs], val);
},
recognizerCreateMethod,
done,
propName + "=" + val
);
})

test("stableIntermediateThreshold", (done: jest.DoneCallback) => {
// tslint:disable-next-line:no-console
console.info("Name: stableIntermediateThreshold");
Expand Down