Skip to content

Instantly share code, notes, and snippets.

@vlcty vlcty/deepspeech.go

Created Apr 4, 2020
Embed
What would you like to do?
Multithreaded deepspeech application executor
package main
import (
"fmt"
"os"
"bufio"
"os/exec"
"time"
"strings"
)
var inputs []string
var inputChannel chan string
func main() {
inputs = make([]string, 0)
inputChannel = make(chan string, 100)
ReadInputFiles()
for i := 0; i < 20; i++ {
go WorkerRoutine()
}
for index, f := range inputs {
inputChannel <- f
if index % 100 == 0 {
fmt.Printf("%d/%d scheduled\n", index, len(inputs))
}
}
time.Sleep(time.Minute * 5)
}
func ReadInputFiles() {
file, fileError := os.Open("wavfiles.txt")
if fileError != nil {
panic(fileError)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
inputs = append(inputs, scanner.Text())
}
}
func WorkerRoutine() {
for {
inputfile := <- inputChannel
command := exec.Command("deepspeech", "--model", "/home/veloc1ty/deepspeech-0.6.1-models/output_graph.pbmm",
"--audio", inputfile)
output, oerr := command.Output()
if oerr != nil {
fmt.Printf("%s -> %s\n", inputfile, oerr.Error())
} else {
fmt.Printf("%s -> %s\n", inputfile, strings.TrimSpace(string(output)))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.