-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
257 additions
and
93 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,5 @@ export { | |
} from "https://deno.land/x/[email protected]/index.js"; | ||
|
||
export { default as $ } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
export { default as OpenAI } from "https://deno.land/x/[email protected]/mod.ts"; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { ModOptions } from "../gen_pack.ts"; | ||
import { bgBlue } from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import { $ } from "../deps.ts"; | ||
import { convertPath } from "../utils/utils.ts"; | ||
import { | ||
checkCommand, | ||
getPico2waveCommand, | ||
} from "../utils/external_commands.ts"; | ||
|
||
let hasPico2waveWslCache: undefined | boolean; | ||
|
||
export async function hasPico2waveWsl() { | ||
if (hasPico2waveWslCache === undefined) { | ||
hasPico2waveWslCache = await checkCommand( | ||
["wsl", "pico2wave", "--version"], | ||
1, | ||
); | ||
} | ||
return hasPico2waveWslCache; | ||
} | ||
|
||
let hasPico2waveCache: undefined | boolean; | ||
|
||
export async function hasPico2wave() { | ||
if (hasPico2waveCache === undefined) { | ||
hasPico2waveCache = await checkCommand(["pico2wave", "--version"], 1); | ||
} | ||
return hasPico2waveCache; | ||
} | ||
|
||
export async function generate_audio_basic_tts( | ||
title: string, | ||
outputPath: string, | ||
lang: string, | ||
opt: ModOptions, | ||
) { | ||
console.log(bgBlue(`Generate basic TTS to ${outputPath}`)); | ||
|
||
if ( | ||
Deno.build.os === "windows" && (opt.skipWsl || !(await hasPico2waveWsl())) | ||
) { | ||
const audioFormat = "[System.Speech.AudioFormat.SpeechAudioFormatInfo]::" + | ||
"new(8000,[System.Speech.AudioFormat.AudioBitsPerSample]" + | ||
"::Sixteen,[System.Speech.AudioFormat.AudioChannel]::Mono)"; | ||
|
||
const args = [ | ||
"-Command", | ||
`Add-Type -AssemblyName System.Speech; ` + | ||
`$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer; ` + | ||
`$speak.SetOutputToWaveFile("${outputPath}",${audioFormat}); ` + | ||
`$speak.Speak(" . ${title.replace(/["' ]/g, " ")} . "); ` + | ||
`$speak.Dispose();`, | ||
]; | ||
await $`PowerShell ${args}`.noThrow(); | ||
} else if (Deno.build.os === "darwin" && !(await hasPico2wave())) { | ||
const args = [ | ||
"-o", | ||
convertPath(outputPath), | ||
"--file-format", | ||
"WAVE", | ||
"--data-format", | ||
"LEF32@22050", | ||
]; | ||
await $`say ${args}`.noThrow(); | ||
} else { | ||
const pico2waveCommand = await getPico2waveCommand(); | ||
const cmd = [ | ||
pico2waveCommand[0], | ||
...(pico2waveCommand.splice(1)), | ||
"-l", | ||
lang, | ||
"-w", | ||
convertPath(outputPath), | ||
` . ${title} . `, | ||
]; | ||
await $`${cmd}`.noThrow(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,20 @@ | ||
import { $, bgBlue } from "../deps.ts"; | ||
import { convertPath } from "../utils/utils.ts"; | ||
import { | ||
checkCommand, | ||
getPico2waveCommand, | ||
} from "../utils/external_commands.ts"; | ||
import { ModOptions } from "../gen_pack.ts"; | ||
import { generate_audio_basic_tts } from "./basic_tts.ts"; | ||
import { generate_audio_with_openAI } from "./openai_tts.ts"; | ||
|
||
let hasPico2waveWslCache: undefined | boolean; | ||
|
||
export async function hasPico2waveWsl() { | ||
if (hasPico2waveWslCache === undefined) { | ||
hasPico2waveWslCache = await checkCommand( | ||
["wsl", "pico2wave", "--version"], | ||
1, | ||
); | ||
} | ||
return hasPico2waveWslCache; | ||
} | ||
|
||
let hasPico2waveCache: undefined | boolean; | ||
|
||
export async function hasPico2wave() { | ||
if (hasPico2waveCache === undefined) { | ||
hasPico2waveCache = await checkCommand(["pico2wave", "--version"], 1); | ||
} | ||
return hasPico2waveCache; | ||
} | ||
|
||
// FIXME : use object args | ||
export async function generateAudio( | ||
title: string, | ||
outputPath: string, | ||
lang: string, | ||
skipWsl: boolean, | ||
opt: ModOptions, | ||
) { | ||
console.log(bgBlue(`Generate audio to ${outputPath}`)); | ||
|
||
if (Deno.build.os === "windows" && (skipWsl || !(await hasPico2waveWsl()))) { | ||
const audioFormat = "[System.Speech.AudioFormat.SpeechAudioFormatInfo]::" + | ||
"new(8000,[System.Speech.AudioFormat.AudioBitsPerSample]" + | ||
"::Sixteen,[System.Speech.AudioFormat.AudioChannel]::Mono)"; | ||
|
||
const args = [ | ||
"-Command", | ||
`Add-Type -AssemblyName System.Speech; ` + | ||
`$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer; ` + | ||
`$speak.SetOutputToWaveFile("${outputPath}",${audioFormat}); ` + | ||
`$speak.Speak(" . ${title.replace(/["' ]/g, " ")} . "); ` + | ||
`$speak.Dispose();`, | ||
]; | ||
await $`PowerShell ${args}`.noThrow(); | ||
} else if (Deno.build.os === "darwin" && !(await hasPico2wave())) { | ||
const args = [ | ||
"-o", | ||
convertPath(outputPath), | ||
"--file-format", | ||
"WAVE", | ||
"--data-format", | ||
"LEF32@22050", | ||
]; | ||
await $`say ${args}`.noThrow(); | ||
if (opt.useOpenAiTts) { | ||
await generate_audio_with_openAI( | ||
title, | ||
outputPath.replace(/\.wav/i, ".mp3"), | ||
opt, | ||
); | ||
} else { | ||
const pico2waveCommand = await getPico2waveCommand(); | ||
const cmd = [ | ||
pico2waveCommand[0], | ||
...(pico2waveCommand.splice(1)), | ||
"-l", | ||
lang, | ||
"-w", | ||
convertPath(outputPath), | ||
` . ${title} . `, | ||
]; | ||
await $`${cmd}`.noThrow(); | ||
await generate_audio_basic_tts(title, outputPath, lang, opt); | ||
} | ||
} |
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
Oops, something went wrong.