[pronunciation assessment] expose word level accuracy score and error… (#695)

This commit is contained in:
Yulin Li 2023-07-21 23:30:50 +08:00 коммит произвёл GitHub
Родитель e1b94900b1
Коммит bca6f1e7cb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 62 добавлений и 3 удалений

Просмотреть файл

@ -58,6 +58,8 @@ export class PronunciationAssessmentConfig {
* @param {string} json The json string containing the pronunciation assessment parameters. * @param {string} json The json string containing the pronunciation assessment parameters.
* @return {PronunciationAssessmentConfig} Instance of PronunciationAssessmentConfig * @return {PronunciationAssessmentConfig} Instance of PronunciationAssessmentConfig
* @summary Creates an instance of the PronunciationAssessmentConfig from json. * @summary Creates an instance of the PronunciationAssessmentConfig from json.
* This method is designed to support the pronunciation assessment parameters still in preview.
* Under normal circumstances, use the constructor instead.
*/ */
public static fromJSON(json: string): PronunciationAssessmentConfig { public static fromJSON(json: string): PronunciationAssessmentConfig {
Contracts.throwIfNullOrUndefined(json, "json"); Contracts.throwIfNullOrUndefined(json, "json");
@ -193,7 +195,11 @@ export class PronunciationAssessmentConfig {
// always set dimension to Comprehensive // always set dimension to Comprehensive
paramsJson.dimension = "Comprehensive"; paramsJson.dimension = "Comprehensive";
paramsJson.enableMiscue = this.enableMiscue;
const enableMiscueString = this.privProperties.getProperty(PropertyId.PronunciationAssessment_EnableMiscue);
if (enableMiscueString) {
paramsJson.enableMiscue = this.enableMiscue;
}
this.privProperties.setProperty(PropertyId.PronunciationAssessment_Params, JSON.stringify(paramsJson)); this.privProperties.setProperty(PropertyId.PronunciationAssessment_Params, JSON.stringify(paramsJson));
} }

Просмотреть файл

@ -29,7 +29,10 @@ interface WordResult {
NBestPhonemes: { Phoneme: string }[]; NBestPhonemes: { Phoneme: string }[];
}; };
}[]; }[];
PronunciationAssessment?: {
AccuracyScore: number;
ErrorType: string;
};
Syllables: { Syllable: string }[]; Syllables: { Syllable: string }[];
} }

Просмотреть файл

@ -150,7 +150,7 @@ describe.each([true, false])("Service based tests", (forceNodeWebSocket: boolean
objsToClose.push(r); objsToClose.push(r);
const p: sdk.PronunciationAssessmentConfig = new sdk.PronunciationAssessmentConfig(Settings.WaveFileText, const p: sdk.PronunciationAssessmentConfig = new sdk.PronunciationAssessmentConfig(Settings.WaveFileText,
PronunciationAssessmentGradingSystem.HundredMark, PronunciationAssessmentGranularity.Phoneme, true); PronunciationAssessmentGradingSystem.HundredMark, PronunciationAssessmentGranularity.Phoneme, false);
objsToClose.push(p); objsToClose.push(p);
p.applyTo(r); p.applyTo(r);
@ -191,6 +191,56 @@ describe.each([true, false])("Service based tests", (forceNodeWebSocket: boolean
}); });
}); });
test("test Pronunciation Assessment with miscue enabled", (done: jest.DoneCallback) => {
// eslint-disable-next-line no-console
console.info("Name: test Pronunciation Assessment with miscue enabled");
const s: sdk.SpeechConfig = BuildSpeechConfig();
objsToClose.push(s);
const r: sdk.SpeechRecognizer = BuildRecognizerFromWaveFile(s, Settings.WaveFile);
objsToClose.push(r);
const p: sdk.PronunciationAssessmentConfig = new sdk.PronunciationAssessmentConfig(Settings.WaveFileText + " buddy",
PronunciationAssessmentGradingSystem.HundredMark, PronunciationAssessmentGranularity.Phoneme, true);
objsToClose.push(p);
p.applyTo(r);
r.canceled = (o: sdk.Recognizer, e: sdk.SpeechRecognitionCanceledEventArgs): void => {
try {
expect(e.errorDetails).toBeUndefined();
} catch (error) {
done(error);
}
};
r.recognizeOnceAsync((result: sdk.SpeechRecognitionResult) => {
try {
expect(result).not.toBeUndefined();
expect(result.errorDetails).toBeUndefined();
expect(result.text).toEqual(Settings.WaveFileText);
expect(result.properties).not.toBeUndefined();
const jsonString = result.properties.getProperty(sdk.PropertyId.SpeechServiceResponse_JsonResult);
expect(jsonString).not.toBeUndefined();
const jsonResult = JSON.parse(jsonString);
expect(jsonResult.SNR).toBeGreaterThan(0);
const pronResult = sdk.PronunciationAssessmentResult.fromResult(result);
expect(pronResult).not.toBeUndefined();
expect(pronResult.detailResult).not.toBeUndefined();
expect(pronResult.detailResult.Words[4].Word).not.toBeUndefined();
expect(pronResult.detailResult.Words[4].PronunciationAssessment.ErrorType).toEqual("Omission")
expect(pronResult.pronunciationScore).toBeGreaterThan(0);
expect(pronResult.accuracyScore).toBeGreaterThan(0);
expect(pronResult.fluencyScore).toBeGreaterThan(0);
expect(pronResult.completenessScore).toBeGreaterThan(0);
done();
} catch (error) {
done(error);
}
}, (error: string) => {
done(error);
});
});
test("test Pronunciation Assessment without reference text", (done: jest.DoneCallback) => { test("test Pronunciation Assessment without reference text", (done: jest.DoneCallback) => {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.info("Name: test Pronunciation Assessment without reference text"); console.info("Name: test Pronunciation Assessment without reference text");