Last active
November 2, 2021 01:11
-
-
Save crashmax-dev/d7c4654722f3555b07bb11eb209ff6ee to your computer and use it in GitHub Desktop.
Text to speech synthesizer (Windows NodeJS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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