Voice generator module

Reviewed-on: #5
Co-authored-by: Oleg Petruny <oleg.petruny@gmail.com>
Co-committed-by: Oleg Petruny <oleg.petruny@gmail.com>
This commit is contained in:
Oleg Petruny 2024-12-13 17:41:14 +01:00 committed by oleg.petruny
parent aa85f56a4c
commit 644083344e
6 changed files with 137 additions and 0 deletions

1
VoiceGenerator/.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
voices/** filter=lfs diff=lfs merge=lfs -text

7
VoiceGenerator/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
*
!.gitignore
!.gitattributes
!GenerateDialogue.py
!install.ps1
!voices/
!voices/**

View File

@ -0,0 +1,12 @@
import torch
from TTS.api import TTS
# Get device
device = "cuda" if torch.cuda.is_available() else "cpu"
tts = TTS("tts_models/multilingual/multi-dataset/bark").to(device)
tts.tts_to_file(text="Greetings Martin. This is a synthesized speech for future dialogues. \
As you can see [cough] I mean hear... Yes, hear with your own ears, the speech trained from 2min audio is indeed impressive.",
voice_dir=".\\voices\\",
speaker="Test",
file_path=".\\output\\Test.wav")

111
VoiceGenerator/Install.ps1 Normal file
View File

@ -0,0 +1,111 @@
$pythonVersion = "3.11.9"
$pythonVersionShort = "3.11"
$pythonInstallerUrl = "https://www.python.org/ftp/python/${pythonVersion}/python-${pythonVersion}-amd64.exe"
$pythonInstallerPath = "$env:TEMP\python-${pythonVersion}.exe"
$pyActivate = Join-Path . "Scripts\Activate.ps1"
$espeakngVersion = "1.51"
$espeakngInstallerUrl = "https://github.com/espeak-ng/espeak-ng/releases/download/${espeakngVersion}/espeak-ng-X64.msi"
$espeakngInstallerPath = "$env:TEMP\espeak-ng-${espeakngVersion}.msi"
$msBuildToolsVersion = "17"
$msBuildToolsInstallerUrl = "https://aka.ms/vs/${msBuildToolsVersion}/release/vs_BuildTools.exe"
$msBuildToolsInstallerPath = "$env:TEMP\vs_BuildTools${msBuildToolsVersion}.exe"
$cudaToolkitVersion = "12.4.1_551.78"
$cudaToolkitInstallerUrl = "https://developer.download.nvidia.com/compute/cuda/12.4.1/local_installers/cuda_${cudaToolkitVersion}_windows.exe"
$cudaToolkitInstallerPath = "$env:TEMP\cudaToolkit_${cudaToolkitVersion}.exe"
$pytorchVersion = "CUDA 12.4"
$pytorchInstallCommand = "pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124"
$coquiVersion = "0.25.1"
$coquiZipUrl = "https://github.com/idiap/coqui-ai-TTS/archive/refs/tags/v$coquiVersion.zip"
$coquiZipPath = "$env:TEMP\coqui_v$coquiVersion.zip"
function Is-PythonInstalled {
try {
$pythonVersionOutput = python --version 2>&1
if ($pythonVersionOutput -match "Python ($pythonVersion)") {
Write-Output "Python $($matches[1]) is already installed."
return $true
} else {
return $false
}
} catch {
return $false
}
}
function Install-Python {
Write-Output "Installing Python $pythonVersion..."
Invoke-WebRequest -Uri $pythonInstallerUrl -OutFile $pythonInstallerPath
Start-Process -FilePath $pythonInstallerPath -ArgumentList "/quiet InstallAllUsers=1 PrependPath=1" -Wait
Remove-Item $pythonInstallerPath -Force
}
function Setup-Python-Environment {
py -$pythonVersionShort -m venv .
& $pyActivate
python -m pip install --upgrade pip setuptools wheel
deactivate
}
function Install-Espeakng {
Write-Output "Installing eSpeak-ng $espeakngVersion..."
Invoke-WebRequest -Uri $espeakngInstallerUrl -OutFile $espeakngInstallerPath
Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"$espeakngInstallerPath`" /passive" -Wait
Remove-Item $espeakngInstallerPath -Force
}
function Install-MsBuildTools {
Write-Output "Installing MS Build Tools $msBuildToolsVersion..."
Invoke-WebRequest -Uri $msBuildToolsInstallerUrl -OutFile $msBuildToolsInstallerPath
Start-Process -FilePath $msBuildToolsInstallerPath -ArgumentList `
"--passive --wait --norestart --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended" -Wait
Remove-Item $msBuildToolsInstallerPath -Force
}
function Install-CUDA {
Write-Output "Installing CUDA Toolkit $cudaToolkitVersion..."
Invoke-WebRequest -Uri $cudaToolkitInstallerUrl -OutFile $cudaToolkitInstallerPath
Start-Process -FilePath $cudaToolkitInstallerPath -ArgumentList "-s -n" -Wait
Remove-Item $cudaToolkitInstallerPath -Force
}
function Install-PyTorch {
Write-Output "Installing PyTorch $pytorchVersion..."
& $pyActivate
Invoke-Expression "$pytorchInstallCommand --quiet"
deactivate
}
function Install-Coqui {
Write-Output "Installing Coqui $coquiVersion..."
Invoke-WebRequest -Uri $coquiZipUrl -OutFile $coquiZipPath
Expand-Archive -Path $coquiZipPath -DestinationPath . -Force
Remove-Item $coquiZipPath -Force
& $pyActivate
cd coqui-ai-TTS-$coquiVersion
pip install -e . --quiet
deactivate
cd ..
}
Write-Output "Starting voice environment installation."
Set-ExecutionPolicy Unrestricted
if (-not (Is-PythonInstalled)) {
Install-Python
}
Setup-Python-Environment
Install-Espeakng
Install-MsBuildTools
Install-CUDA
Install-PyTorch
Install-Coqui
mkdir output
Write-Output "Setup finished. Please restart your machine before first startup."
Write-Output "To generate dialogue type in PS terminal in VoiceGenerator directory:`n 1] .\Scripts\Activate.ps1`n 2] py GenerateDialogue.py."

BIN
VoiceGenerator/voices/Test/Test.npz (Stored with Git LFS) Normal file

Binary file not shown.

BIN
VoiceGenerator/voices/Test/Test.wav (Stored with Git LFS) Normal file

Binary file not shown.