Skip to content

Commit

Permalink
restructure project to support both CLI and library usage
Browse files Browse the repository at this point in the history
  • Loading branch information
shinshin86 committed Dec 1, 2024
1 parent daefe93 commit 2e9e7a9
Show file tree
Hide file tree
Showing 5 changed files with 358 additions and 224 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
vpeak
/vpeak
.DS_Store
132 changes: 124 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
# vpeak
CLI tool to touch [VOICEPEAK](https://www.ah-soft.com/voice/6nare/) from the command line.
`vpeak` is a tool that allows you to interact with [VOICEPEAK](https://www.ah-soft.com/voice/6nare/) from the command line or within your Go applications.

## Usage
## Features

Execute the following command to speak the string passed as an argument.
- **CLI Tool**: Use `vpeak` from the command line to generate speech audio.
- **Go Library**: Import `vpeak` into your Go projects to generate speech programmatically.

---
## CLI Usage

Execute the following command to have VOICEPEAK speak the string passed as an argument:

```sh
# # 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 "こんにちは"
```

Expand All @@ -29,7 +37,7 @@ vpeak -n f1 -e happy -o your-dir-2 -d your-dir

### Silent mode

With the `-silent` option, no voice reading is performed. It also does not automatically delete the generated files. This option is useful for only generating audio files.
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 "こんにちは"
Expand All @@ -47,16 +55,124 @@ Run the `help` command for more information.
vpeak -h
```

---
## Library Usage

You can also use `vpeak` as a Go library in your own applications.

### Installation

To install the library, run:

```sh
go get github.com/shinshin86/vpeak@latest
```

### Importing the Library

In your Go code, import the `vpeak` package:

```go
import "github.com/shinshin86/vpeak"
```

### Example Usage

Here's an example of how to use `vpeak` in your Go program:

```go
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.")
}
```

### Options

- `Narrator`: Choose the narrator's voice. Available options:
- `f1`: Japanese Female 1
- `f2`: Japanese Female 2
- `f3`: Japanese Female 3
- `m1`: Japanese Male 1
- `m2`: Japanese Male 2
- `m3`: Japanese Male 3
- `c`: 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 to `output.wav`.
- `Silent`: Set to `true` to disable voice playback.

### Processing Text Files in a Directory

You can also process all text files in a directory:

```go
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.")
}
```

---

## Support
Tested only under the following conditions.
vpeak is currently tested under the following conditions. Compatibility with other environments is not guaranteed.

### OS
Currently only **M1 or later(arm64) mac** are supported
- M1 or later (arm64) Macs only.

### VOICEPEAK
VOICEPEAK must be updated to the latest version in order to use vpeak.
I am testing with 1.2.7.
- VOICEPEAK must be updated to the latest version.
- Tested with version **1.2.7**.

## Notes

- 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 the `VoicepeakPath` constant in the code.
- The library functions provide error handling by returning errors, allowing you to handle them appropriately in your application.

## License
[MIT](./LICENSE)
Expand Down
72 changes: 72 additions & 0 deletions cmd/vpeak/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package main

import (
"flag"
"fmt"
"log"
"os"

"github.com/shinshin86/vpeak"
)

func main() {
var (
dirOpt = flag.String("d", "", "Directory to read files from")
outputOpt = flag.String("o", "", "Output file path (Specify the name of the output directory if reading by directory (-d option))")
narratorOpt = flag.String("n", "", "Specify the narrator. See below for options.")
emotionOpt = flag.String("e", "", "Specify the emotion. See below for options.")
silentOpt = flag.Bool("silent", false, "Silent mode (no sound)")
)

flag.Usage = func() {
fmt.Printf("Usage: %s [OPTIONS] <text>\n", os.Args[0])
fmt.Println("Options:")
flag.PrintDefaults()
fmt.Println("\nNarrator options:")
fmt.Println(" f1: Japanese Female 1")
fmt.Println(" f2: Japanese Female 2")
fmt.Println(" f3: Japanese Female 3")
fmt.Println(" m1: Japanese Male 1")
fmt.Println(" m2: Japanese Male 2")
fmt.Println(" m3: Japanese Male 3")
fmt.Println(" c: Japanese Female Child")
fmt.Println("\nEmotion options:")
fmt.Println(" happy")
fmt.Println(" fun")
fmt.Println(" angry")
fmt.Println(" sad")
}

help := flag.Bool("help", false, "Show help")

flag.Parse()

if *help {
flag.Usage()
os.Exit(0)
}

if len(flag.Args()) == 0 && *dirOpt == "" {
log.Fatalf("Usage: %s [-n] <text>", os.Args[0])
}

opts := vpeak.Options{
Narrator: *narratorOpt,
Emotion: *emotionOpt,
Output: *outputOpt,
Silent: *silentOpt,
}

if *dirOpt == "" {
text := flag.Args()[0]
if err := vpeak.GenerateSpeech(text, opts); err != nil {
log.Fatalf("Error: %v", err)
}
} else {
if err := vpeak.ProcessTextFiles(*dirOpt, opts); err != nil {
log.Fatalf("Error: %v", err)
}
}

fmt.Println("Commands executed successfully")
}
Loading

0 comments on commit 2e9e7a9

Please sign in to comment.