diff --git a/platform/base.js b/platform/base.js index b8b1556..dc214f7 100644 --- a/platform/base.js +++ b/platform/base.js @@ -1,5 +1,6 @@ const childProcess = require('child_process') const once = require('one-time') +const symbolTTS = require('../symbol-tts.js') class SayPlatformBase { constructor () { @@ -28,7 +29,11 @@ class SayPlatformBase { }) } - let { command, args, pipedData, options } = this.buildSpeakCommand({ text, voice, speed }) + let { command, args, pipedData, options } = this.buildSpeakCommand({ + text: symbolTTS(text), + voice, + speed + }) this.child = childProcess.spawn(command, args, options) @@ -84,7 +89,12 @@ class SayPlatformBase { } try { - var { command, args, pipedData, options } = this.buildExportCommand({ text, voice, speed, filename }) + var { command, args, pipedData, options } = this.buildExportCommand({ + text: symbolTTS(text), + voice, + speed, + filename + }) } catch (error) { return setImmediate(() => { callback(error) diff --git a/symbol-tts.js b/symbol-tts.js new file mode 100644 index 0000000..5c29787 --- /dev/null +++ b/symbol-tts.js @@ -0,0 +1,46 @@ +// This file converts symbols into their audible form +// It's essentially a tool for 'escaping' characters for TTS purposes +const lookup = new Map() + +// lookup.set(/!/g, ' exclamation mark ') +lookup.set(/@/g, ' at ') +lookup.set(/#/g, ' octothorpe ') +lookup.set(/\$/g, ' dollar sign ') +lookup.set(/%/g, ' percent ') +lookup.set(/\^/g, ' caret ') +lookup.set(/&/g, ' and ') +lookup.set(/\*/g, ' asterisk ') +lookup.set(/\(/g, ' left paren ') +lookup.set(/\)/g, ' right paren ') +lookup.set(/-/g, ' minus ') +lookup.set(/\+/g, ' plus ') +lookup.set(/_/g, ' underscore ') +lookup.set(/=/g, ' equals ') +lookup.set(/"/g, ' quote ') +// lookup.set(/'/g, ' single quote ') // would break words like "don't" +lookup.set(/\]/g, ' right bracket ') +lookup.set(/\[/g, ' left bracket ') +lookup.set(/\}/g, ' right curly ') +lookup.set(/\{/g, ' left curly ') +lookup.set(/\|/g, ' pipe ') +lookup.set(/\//g, ' slash ') +lookup.set(/\\/g, ' backslash ') +// lookup.set(/:/g, ' colon ') +// lookup.set(/;/g, ' semicolon ') +// lookup.set(/./g, ' period ') +// lookup.set(/,/g, ' comma ') +// lookup.set(/?/g, ' question mark ') +lookup.set(/`/g, ' backtick ') +lookup.set(/~/g, ' tilde ') +lookup.set(/>/g, ' greater than ') +lookup.set(/ { + lookup.forEach((after, before) => { + text = text.replace(before, after) + }) + + return text +}