in experiments/babel/main.go [60:124]
func main() {
// project setup
// Get Google Cloud Project ID from environment variable
projectID = envCheck("PROJECT_ID", "") // no default
if projectID == "" {
log.Fatalf("please set env var PROJECT_ID with google cloud project, e.g. export PROJECT_ID=$(gcloud config get project)")
}
// Get Google Cloud Region from environment variable
location = envCheck("REGION", "us-central1") // default is us-central1
// get all Chirp-HD voices
var err error
voices, err = listChirpHDVoices()
if err != nil {
log.Fatalf("cannot listChirpHDVoices: %v", err)
}
log.Printf("%d Chirp-HD voices", len(voices))
// run as service, env var precedence
service = envCheck("SERVICE", service)
if service != "false" {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
babelbucket = envCheck("BABEL_BUCKET", fmt.Sprintf("%s-fabulae", projectID))
babelpath = envCheck("BABEL_PATH", "babel")
log.Printf("using gs://%s/%s", babelbucket, babelpath)
http.HandleFunc("POST /babel", handleSynthesis)
http.HandleFunc("GET /voices", handleListVoices)
http.ListenAndServe(fmt.Sprintf(":%s", port), nil)
}
// statement ingestion
statement := strings.Join(flag.Args(), " ")
log.Printf("original statement: %s", statement)
// get all languages
languages := getAllLanguages()
// translate to each language
translateSpinner := progressbar.NewOptions(
-1,
progressbar.OptionSetDescription("translating statement ..."),
progressbar.OptionSetWidth(15),
)
translateSpinner.Add(1)
translations := translate(statement, languages)
translateSpinner.Finish()
fmt.Println()
// tts and write to file
audioGenerationSpinner := progressbar.NewOptions(
-1,
progressbar.OptionSetDescription("generating audio ..."),
progressbar.OptionSetWidth(15),
)
audioGenerationSpinner.Add(1)
outputfiles := generateSpeech(voices, translations)
audioGenerationSpinner.Finish()
fmt.Println()
log.Printf("complete. wrote %d files", len(outputfiles))
}