Added first draft.

This commit is contained in:
patelravi 2019-03-22 17:00:05 +05:30
parent 72b7b8f0a5
commit abed1ca604
5 changed files with 77 additions and 8 deletions

View file

@ -45,7 +45,7 @@ gulp.task('test', ['pre-test'], function (cb) {
console.log('Running tests with node version', process.version);
gulp.src('test/**/*.js')
gulp.src('test/**/ssml.js')
.pipe(plumber())
.pipe(mocha({ reporter: 'spec' }))
.on('error', function (err) {

View file

@ -54,3 +54,38 @@ export function camelCaseRequestWrapper(requestFunc) {
}
}
export function validateVoiceForSsml(voice, language) {
var voiceParts = voice.split('.');
if (['MAN', 'WOMAN'].indexOf(voice) != -1) {
return { success: true };
} else if (voiceParts.length != 2 || voiceParts[0] != 'Polly') {
return {
success: false, msg: "Invalid voice " + voice + '.'
};
}
// If voice is polly, validate accent based on language specified
// List of valid Polly voices
var languageWiseVoices = {
'Australian English': ['Nicole', 'Russell'],
'Brazilian Portuguese': ['Vitória', 'Ricardo']
};
// Validate supported languages.
if (!languageWiseVoices[language]) {
return {
success: false, msg: "Invalid language."
};
}
// Validate voice for given language.
if (languageWiseVoices[language].indexOf(voiceParts[1]) == -1) {
return {
success: false, msg: "XML Validation Error: <Speak> voice " + voice + " is not valid. Refer <link> for list of supported voices."
};
}
}

View file

@ -1,6 +1,7 @@
export class PlivoRestError extends Error {}
export class ResourceNotFoundError extends PlivoRestError {}
export class ServerError extends PlivoRestError {}
export class InvalidRequestError extends PlivoRestError {}
export class PlivoXMLError extends PlivoRestError {}
export class AuthenticationError extends PlivoRestError {}
export class PlivoRestError extends Error { }
export class ResourceNotFoundError extends PlivoRestError { }
export class ServerError extends PlivoRestError { }
export class InvalidRequestError extends PlivoRestError { }
export class PlivoXMLError extends PlivoRestError { }
export class PlivoXMLValidationError extends PlivoRestError { }
export class AuthenticationError extends PlivoRestError { }

File diff suppressed because one or more lines are too long

12
test/ssml.js Normal file
View file

@ -0,0 +1,12 @@
import assert from 'assert';
import sinon from 'sinon';
import { Response, Client } from '../lib/rest/client';
import { PlivoGenericResponse } from '../lib/base.js';
let client = new Client('sampleid', 'sammpletoken', 'sampleproxy');
let response = new Response();
let speak_body = "Hello, world!";
response.addSpeak(speak_body, { voice: 'SRD' });
console.log(response.toXML());