Skip to content

Instantly share code, notes, and snippets.

@crashmax-dev
Last active November 2, 2021 01:11
Show Gist options
  • Save crashmax-dev/d7c4654722f3555b07bb11eb209ff6ee to your computer and use it in GitHub Desktop.
Save crashmax-dev/d7c4654722f3555b07bb11eb209ff6ee to your computer and use it in GitHub Desktop.
Text to speech synthesizer (Windows NodeJS)
import { exec } from 'child_process'
const speed = 5
const volume = 35
// get installed voices
// Add-Type -AssemblyName System.speech;$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer;$speak.GetInstalledVoices() | % {$_.VoiceInfo.Name}
const voice = 'Microsoft Irina Desktop'
const message = 'Привет'
// filtering special characters
message.replace(/[&'<>]/gi, '')
let cmd = 'powershell.exe Add-Type -AssemblyName System.speech; $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer;'
cmd += `$speak.SelectVoice('${voice}');`
cmd += `$speak.Volume = ${volume};`
cmd += `$speak.Rate = ${speed};`
cmd += `$speak.Speak('${message}');`
exec(cmd, (err) => {
console.log(err ?? 'working!')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment