mirror of
https://github.com/donl/plivo-node.git
synced 2026-05-25 22:07:10 -06:00
Added first draft.
This commit is contained in:
parent
72b7b8f0a5
commit
abed1ca604
5 changed files with 77 additions and 8 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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."
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
12
test/ssml.js
Normal 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());
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue