From 3f82b92ca21101d519c915ca6d45b633a9bede2f Mon Sep 17 00:00:00 2001 From: Nicholas Suski Date: Sun, 17 Nov 2019 23:43:39 -0700 Subject: [PATCH 1/3] Implement initial version of speakText --- __tests__/actions/speakText.spec.ts | 55 +++++++++++++++++++ src/actions/index.ts | 2 + src/actions/speakText.ts | 52 ++++++++++++++++++ .../WF/WFWorkflowActionIdentifier.ts | 1 + .../WF/WFWorkflowActionParameters.ts | 6 ++ 5 files changed, 116 insertions(+) create mode 100644 __tests__/actions/speakText.spec.ts create mode 100644 src/actions/speakText.ts diff --git a/__tests__/actions/speakText.spec.ts b/__tests__/actions/speakText.spec.ts new file mode 100644 index 00000000..b73722cf --- /dev/null +++ b/__tests__/actions/speakText.spec.ts @@ -0,0 +1,55 @@ +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: 1.0, + WFText: '', + 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 testText = 'Hello World'; + const testVoice = 'Irish'; + const testWaitUntilFinished = false; + + const expected = { + WFWorkflowActionIdentifier: 'is.workflow.actions.speaktext', + WFWorkflowActionParameters: { + WFSpeakTextLanguage: testLanguage, + WFSpeakTextPitch: testPitch, + WFSpeakTextRate: testRate, + WFText: testText, + WFSpeakTextVoice: testVoice, + WFSpeakTextWait: testWaitUntilFinished, + }, + }; + const actual = speakText({ + language: 'English', + pitch: 0.75, + rate: 0.5, + text: 'Hello World', + voice: 'Irish', + waitUntilFinished: false, + }); + + expect(actual).toEqual(expected); + }); +}); diff --git a/src/actions/index.ts b/src/actions/index.ts index b4fe810b..0689baf1 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -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'; @@ -244,6 +245,7 @@ export { showResult, skipBack, skipForward, + speakText, text, tweet, trimMedia, diff --git a/src/actions/speakText.ts b/src/actions/speakText.ts new file mode 100644 index 00000000..d5112aef --- /dev/null +++ b/src/actions/speakText.ts @@ -0,0 +1,52 @@ +import WFSerialization from '../interfaces/WF/WFSerialization'; +import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction'; + +/** + * @action Speak Text + * @section Content Types > Documents > Speak Text + * @icon Documents + * + * Speaks the inputted text aloud. + * + * ```js + * speakText({ + * text: 'Some lovely text!', + * }); + * ``` + */ + +const speakText = ( + { + language = 'Default', + pitch = 1.0, + rate = 1.0, + text = '', + voice = 'Default', + waitUntilFinished = true, + }: { + /** The language to use when speaking text */ + language?: string, // TODO: --------verify type is correct.---------- + /** The pitch to use when speaking text */ + pitch?: number + /** The rate to use when speaking text */ + rate?: number + /** The text to speak */ + text?: WFSerialization | string, + /** The voice to use when speaking text */ + voice?: string, // TODO: --------verify type is correct.---------- + /** 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, + WFText: text, + WFSpeakTextVoice: voice, + WFSpeakTextWait: waitUntilFinished, + }, +}); + +export default speakText; diff --git a/src/interfaces/WF/WFWorkflowActionIdentifier.ts b/src/interfaces/WF/WFWorkflowActionIdentifier.ts index f5515845..0ea8e373 100644 --- a/src/interfaces/WF/WFWorkflowActionIdentifier.ts +++ b/src/interfaces/WF/WFWorkflowActionIdentifier.ts @@ -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' diff --git a/src/interfaces/WF/WFWorkflowActionParameters.ts b/src/interfaces/WF/WFWorkflowActionParameters.ts index a1553e79..bea0e0b0 100644 --- a/src/interfaces/WF/WFWorkflowActionParameters.ts +++ b/src/interfaces/WF/WFWorkflowActionParameters.ts @@ -116,7 +116,13 @@ interface WFWorkflowActionParameters { WFSSHScript?: WFSerialization | string; WFSSHUser?: WFSerialization | string; WFSkipBackBehavior?: WFSkipBackBehavior; + WFSpeakTextLanguage?: string; // TODO: Make a type? + WFSpeakTextPitch?: number; + WFSpeakTextRate?: number; + WFSpeakTextVoice?: string; // TODO: Make a type? + WFSpeakTextWait?: boolean; WFStatisticsOperation?: WFSerialization | WFStatisticsOperation; + WFText?: WFSerialization | string; WFTextActionText?: WFSerialization | string; WFTime?: WFSerialization | string; WFTimeFormatStyle?: WFSerialization | WFTimeFormatStyle; From 9dfaa3836be351bf0115779382a22e8496117a67 Mon Sep 17 00:00:00 2001 From: Nicholas Suski Date: Mon, 18 Nov 2019 00:18:00 -0700 Subject: [PATCH 2/3] Adjust default values --- __tests__/actions/speakText.spec.ts | 6 +----- src/actions/speakText.ts | 18 +++++++++--------- .../WF/WFWorkflowActionParameters.ts | 4 ++-- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/__tests__/actions/speakText.spec.ts b/__tests__/actions/speakText.spec.ts index b73722cf..ff5a16b0 100644 --- a/__tests__/actions/speakText.spec.ts +++ b/__tests__/actions/speakText.spec.ts @@ -11,8 +11,7 @@ describe('speakText function', () => { WFWorkflowActionParameters: { WFSpeakTextLanguage: 'Default', WFSpeakTextPitch: 1.0, - WFSpeakTextRate: 1.0, - WFText: '', + WFSpeakTextRate: 0.5, WFSpeakTextVoice: 'Default', WFSpeakTextWait: true, }, @@ -26,7 +25,6 @@ describe('speakText function', () => { const testLanguage = 'English'; const testPitch = 0.75; const testRate = 0.5; - const testText = 'Hello World'; const testVoice = 'Irish'; const testWaitUntilFinished = false; @@ -36,7 +34,6 @@ describe('speakText function', () => { WFSpeakTextLanguage: testLanguage, WFSpeakTextPitch: testPitch, WFSpeakTextRate: testRate, - WFText: testText, WFSpeakTextVoice: testVoice, WFSpeakTextWait: testWaitUntilFinished, }, @@ -45,7 +42,6 @@ describe('speakText function', () => { language: 'English', pitch: 0.75, rate: 0.5, - text: 'Hello World', voice: 'Irish', waitUntilFinished: false, }); diff --git a/src/actions/speakText.ts b/src/actions/speakText.ts index d5112aef..bcf54a33 100644 --- a/src/actions/speakText.ts +++ b/src/actions/speakText.ts @@ -1,4 +1,3 @@ -import WFSerialization from '../interfaces/WF/WFSerialization'; import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction'; /** @@ -10,7 +9,12 @@ import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction'; * * ```js * speakText({ - * text: 'Some lovely text!', + * text: 'Well hello there!', + * language: 'Default', + * pitch: 1.0, + * rate: 0, + * voice: 'Default', + * waitUntilFinished: true, * }); * ``` */ @@ -19,21 +23,18 @@ const speakText = ( { language = 'Default', pitch = 1.0, - rate = 1.0, - text = '', + rate = 0.5, voice = 'Default', waitUntilFinished = true, }: { /** The language to use when speaking text */ - language?: string, // TODO: --------verify type is correct.---------- + language?: string, /** The pitch to use when speaking text */ pitch?: number /** The rate to use when speaking text */ rate?: number - /** The text to speak */ - text?: WFSerialization | string, /** The voice to use when speaking text */ - voice?: string, // TODO: --------verify type is correct.---------- + voice?: string, /** Should we wait until the speaking is finished to run the next action */ waitUntilFinished?: boolean, }, @@ -43,7 +44,6 @@ const speakText = ( WFSpeakTextLanguage: language, WFSpeakTextPitch: pitch, WFSpeakTextRate: rate, - WFText: text, WFSpeakTextVoice: voice, WFSpeakTextWait: waitUntilFinished, }, diff --git a/src/interfaces/WF/WFWorkflowActionParameters.ts b/src/interfaces/WF/WFWorkflowActionParameters.ts index bea0e0b0..34eab3ab 100644 --- a/src/interfaces/WF/WFWorkflowActionParameters.ts +++ b/src/interfaces/WF/WFWorkflowActionParameters.ts @@ -116,10 +116,10 @@ interface WFWorkflowActionParameters { WFSSHScript?: WFSerialization | string; WFSSHUser?: WFSerialization | string; WFSkipBackBehavior?: WFSkipBackBehavior; - WFSpeakTextLanguage?: string; // TODO: Make a type? + WFSpeakTextLanguage?: string; WFSpeakTextPitch?: number; WFSpeakTextRate?: number; - WFSpeakTextVoice?: string; // TODO: Make a type? + WFSpeakTextVoice?: string; WFSpeakTextWait?: boolean; WFStatisticsOperation?: WFSerialization | WFStatisticsOperation; WFText?: WFSerialization | string; From c6f754bf9c2675742a7f0f6693289a04b60b52e1 Mon Sep 17 00:00:00 2001 From: Nicholas Suski Date: Mon, 18 Nov 2019 00:25:39 -0700 Subject: [PATCH 3/3] Correct error in example --- src/actions/speakText.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/actions/speakText.ts b/src/actions/speakText.ts index bcf54a33..837fc292 100644 --- a/src/actions/speakText.ts +++ b/src/actions/speakText.ts @@ -9,7 +9,6 @@ import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction'; * * ```js * speakText({ - * text: 'Well hello there!', * language: 'Default', * pitch: 1.0, * rate: 0,