Skip to content

Instantly share code, notes, and snippets.

@vlcty
Created April 4, 2020 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vlcty/5edfe4727fc7e9bb01454eccdb2ab4ce to your computer and use it in GitHub Desktop.
Save vlcty/5edfe4727fc7e9bb01454eccdb2ab4ce to your computer and use it in GitHub Desktop.
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