Skip to content

Commit

Permalink
Merge pull request #311 from n33kos/speakText
Browse files Browse the repository at this point in the history
Add speakText
  • Loading branch information
joshfarrant committed Nov 19, 2019
2 parents a656e7a + c6f754b commit 9fee11f
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
51 changes: 51 additions & 0 deletions __tests__/actions/speakText.spec.ts
@@ -0,0 +1,51 @@
import { speakText } from '../../src/actions';

describe('speakText function', () => {
it('is a function', () => {
expect(typeof speakText).toBe('function');
});

it('builds a speakText action when no parameters are passed', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.speaktext',
WFWorkflowActionParameters: {
WFSpeakTextLanguage: 'Default',
WFSpeakTextPitch: 1.0,
WFSpeakTextRate: 0.5,
WFSpeakTextVoice: 'Default',
WFSpeakTextWait: true,
},
};
const actual = speakText({});

expect(actual).toEqual(expected);
});

it('builds a text action when parameters are passed', () => {
const testLanguage = 'English';
const testPitch = 0.75;
const testRate = 0.5;
const testVoice = 'Irish';
const testWaitUntilFinished = false;

const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.speaktext',
WFWorkflowActionParameters: {
WFSpeakTextLanguage: testLanguage,
WFSpeakTextPitch: testPitch,
WFSpeakTextRate: testRate,
WFSpeakTextVoice: testVoice,
WFSpeakTextWait: testWaitUntilFinished,
},
};
const actual = speakText({
language: 'English',
pitch: 0.75,
rate: 0.5,
voice: 'Irish',
waitUntilFinished: false,
});

expect(actual).toEqual(expected);
});
});
2 changes: 2 additions & 0 deletions src/actions/index.ts
Expand Up @@ -114,6 +114,7 @@ import showNotification from './showNotification';
import showResult from './showResult';
import skipBack from './skipBack';
import skipForward from './skipForward';
import speakText from './speakText';
import text from './text';
import trimMedia from './trimMedia';
import tweet from './tweet';
Expand Down Expand Up @@ -244,6 +245,7 @@ export {
showResult,
skipBack,
skipForward,
speakText,
text,
tweet,
trimMedia,
Expand Down
51 changes: 51 additions & 0 deletions src/actions/speakText.ts
@@ -0,0 +1,51 @@
import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction';

/**
* @action Speak Text
* @section Content Types > Documents > Speak Text
* @icon Documents
*
* Speaks the inputted text aloud.
*
* ```js
* speakText({
* language: 'Default',
* pitch: 1.0,
* rate: 0,
* voice: 'Default',
* waitUntilFinished: true,
* });
* ```
*/

const speakText = (
{
language = 'Default',
pitch = 1.0,
rate = 0.5,
voice = 'Default',
waitUntilFinished = true,
}: {
/** The language to use when speaking text */
language?: string,
/** The pitch to use when speaking text */
pitch?: number
/** The rate to use when speaking text */
rate?: number
/** The voice to use when speaking text */
voice?: string,
/** Should we wait until the speaking is finished to run the next action */
waitUntilFinished?: boolean,
},
): WFWorkflowAction => ({
WFWorkflowActionIdentifier: 'is.workflow.actions.speaktext',
WFWorkflowActionParameters: {
WFSpeakTextLanguage: language,
WFSpeakTextPitch: pitch,
WFSpeakTextRate: rate,
WFSpeakTextVoice: voice,
WFSpeakTextWait: waitUntilFinished,
},
});

export default speakText;
1 change: 1 addition & 0 deletions src/interfaces/WF/WFWorkflowActionIdentifier.ts
Expand Up @@ -111,6 +111,7 @@ type WFWorkflowActionIdentifier = (
| 'is.workflow.actions.showresult'
| 'is.workflow.actions.skipback'
| 'is.workflow.actions.skipforward'
| 'is.workflow.actions.speaktext'
| 'is.workflow.actions.statistics'
| 'is.workflow.actions.text.changecase'
| 'is.workflow.actions.text.match'
Expand Down
6 changes: 6 additions & 0 deletions src/interfaces/WF/WFWorkflowActionParameters.ts
Expand Up @@ -116,7 +116,13 @@ interface WFWorkflowActionParameters {
WFSSHScript?: WFSerialization | string;
WFSSHUser?: WFSerialization | string;
WFSkipBackBehavior?: WFSkipBackBehavior;
WFSpeakTextLanguage?: string;
WFSpeakTextPitch?: number;
WFSpeakTextRate?: number;
WFSpeakTextVoice?: string;
WFSpeakTextWait?: boolean;
WFStatisticsOperation?: WFSerialization | WFStatisticsOperation;
WFText?: WFSerialization | string;
WFTextActionText?: WFSerialization | string;
WFTime?: WFSerialization | string;
WFTimeFormatStyle?: WFSerialization | WFTimeFormatStyle;
Expand Down

0 comments on commit 9fee11f

Please sign in to comment.