Orion/orion.go

104 lines
2.4 KiB
Go

/*
Orion --- Speech to text bot
Copyright (c) 2022 Sameer Rahmani <lxsameer@gnu.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"path/filepath"
"github.com/asticode/go-asticoqui"
"github.com/joho/godotenv"
"lxsameer.com/go/orion/pkg/core"
)
var model = flag.String("model", "models/default.tflite", "Path to the model (protocol buffer binary file)")
var scorer = flag.String("scorer", "models/default.scorer", "Path to the external scorer")
var owner = flag.String("owner", "", "Telegram user id that is allowed to use this bot")
var storage = flag.String("voice-storage", "", "Where to store the voices")
func main() {
flag.Parse()
log.SetFlags(0)
err := godotenv.Load(".env")
if err != nil {
log.Fatal(err)
return
}
if *model == "" || *scorer == "" {
// In case of error print error and print usage
// This can also be done by passing -h or --help flags
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
return
}
if *storage == "" {
dir, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
return
}
*storage = filepath.Join(dir, ".orion", "storage")
}
bot, err := core.CreateBot(storage)
if err != nil {
log.Fatal(err)
return
}
bot.Owner = *owner
// Initialize Coqui
m, err := asticoqui.New(*model)
if err != nil {
log.Fatal("Failed initializing model: ", err)
}
if err := m.EnableExternalScorer(*scorer); err != nil {
log.Fatal("Failed enabling external scorer: ", err)
return
}
bot.Model = m
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func(){
for range c {
bot.ShutDown()
os.Exit(0)
}
}()
bot.StartBot()
// a1 := "/home/lxsameer/src/orion/2022-04-09_11:48:57.ogg"
// a2 := "/home/lxsameer/src/orion/blah.wav"
// err = core.ConvertOggtoWav(&a1, &a2)
log.Println("done!")
}