Created
April 4, 2020 16:27
-
-
Save vlcty/5edfe4727fc7e9bb01454eccdb2ab4ce to your computer and use it in GitHub Desktop.
Multithreaded deepspeech application executor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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