vpeak
is a tool that allows you to interact with VOICEPEAK from the command line or within your Go applications.
- CLI Tool: Use
vpeak
from the command line to generate speech audio. - Go Library: Import
vpeak
into your Go projects to generate speech programmatically.
To install vpeak
as a CLI tool, run the following command:
go install github.com/shinshin86/vpeak/cmd/vpeak@latest
This will download, build, and install the vpeak binary to your $GOBIN directory (usually $HOME/go/bin).
Execute the following command to have VOICEPEAK speak the string passed as an argument:
# # not option specfied (narrator: Japanese Female Child, emotion: natural)
vpeak こんにちは!
# option (narrator: Japanese Female 1, emotion: happy)
vpeak -n f1 -e happy "こんにちは"
# option (narrator: Japanese Female 1, emotion: happy, output path: ./hello.wav)
# (An audio file will only be generated if the output option is specified, and it will be saved at the designated location.)
vpeak -n f1 -e happy -o ./hello.wav "こんにちは"
Converts all text files(.txt
) in the directory specified by the -d
option to audio files (.wav
).
vpeak -d your-dir
# option (narrator: Japanese Female 1, emotion: happy)
vpeak -n f1 -e happy -d your-dir
# option (narrator: Japanese Female 1, emotion: happy, output dir: your-dir-2)
vpeak -n f1 -e happy -o your-dir-2 -d your-dir
When the -silent
option is used, no voice playback is performed, and the generated files are not automatically deleted. This option is useful if you only want to generate audio files.
vpeak -silent "こんにちは"
The audio file will remain only if outputPath is specified, executed per directory, or silent mode is enabled.
Run the help
command for more information.
vpeak -h
You can also use vpeak
as a Go library in your own applications.
To install the library, run:
go get github.com/shinshin86/vpeak@latest
In your Go code, import the vpeak
package:
import "github.com/shinshin86/vpeak"
Here's an example of how to use vpeak
in your Go program:
package main
import (
"fmt"
"log"
"github.com/shinshin86/vpeak"
)
func main() {
text := "こんにちは"
opts := vpeak.Options{
Narrator: "f1", // Narrator option (e.g., "f1", "m1")
Emotion: "happy", // Emotion option (e.g., "happy", "sad")
Output: "hello.wav",// Output file path
Silent: false, // Silent mode (true or false)
}
if err := vpeak.GenerateSpeech(text, opts); err != nil {
log.Fatalf("Failed to generate speech: %v", err)
}
fmt.Println("Speech generated successfully.")
}
Narrator
: Choose the narrator's voice. Available options:f1
: Japanese Female 1f2
: Japanese Female 2f3
: Japanese Female 3m1
: Japanese Male 1m2
: Japanese Male 2m3
: Japanese Male 3c
: Japanese Female Child
Emotion
: Choose the emotion. Available options:happy
fun
angry
sad
- If no option is specified, it will be
natural
.
Output
: Specify the output file path. If not set, defaults tooutput.wav
.Silent
: Set totrue
to disable voice playback.
You can also process all text files in a directory:
package main
import (
"fmt"
"log"
"github.com/shinshin86/vpeak"
)
func main() {
dir := "your-dir"
opts := vpeak.Options{
Narrator: "f1",
Emotion: "happy",
Output: "your-dir-2", // Output directory
Silent: true,
}
if err := vpeak.ProcessTextFiles(dir, opts); err != nil {
log.Fatalf("Failed to process text files: %v", err)
}
fmt.Println("Text files processed successfully.")
}
vpeak is currently tested under the following conditions. Compatibility with other environments is not guaranteed.
- M1 or later (arm64) Macs only.
- VOICEPEAK must be updated to the latest version.
- Tested with version 1.2.7.
- Ensure that VOICEPEAK is installed at the path specified in the code (
/Applications/voicepeak.app/Contents/MacOS/voicepeak
). If it is installed elsewhere, you may need to adjust theVoicepeakPath
constant in the code. - The library functions provide error handling by returning errors, allowing you to handle them appropriately in your application.