Add the org-mode entry
This commit is contained in:
parent
284d99fa16
commit
a62f59a73d
|
@ -8,11 +8,13 @@ In order to use it, first you need to setup the project which you can just call
|
||||||
following command:
|
following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./builder run -owner TELEGRAM_ID -model PATH_TO_MODEL -scorer PATH_TO_SCORER
|
./builder run -owner TELEGRAM_ID -org-file ORG_FILE_PATH -model PATH_TO_MODEL -scorer PATH_TO_SCORER
|
||||||
```
|
```
|
||||||
* **TELEGRAM_ID**: Is your telegram id. It will only reply to you and tell others
|
* **TELEGRAM_ID**: Is your telegram id. It will only reply to you and tell others
|
||||||
to F off.
|
to F off.
|
||||||
|
|
||||||
|
* **ORG_FILE_PATH**: Path to an `org-mode` file that **HAS TO EXIST**. Orion will append entries
|
||||||
|
to this file.
|
||||||
* **PATH_TO_MODEL(optoinal)**: Is the path to the model file you want to use for speech recognition.
|
* **PATH_TO_MODEL(optoinal)**: Is the path to the model file you want to use for speech recognition.
|
||||||
the default points to the default model in the models directory.
|
the default points to the default model in the models directory.
|
||||||
|
|
||||||
|
|
5
orion.go
5
orion.go
|
@ -33,6 +33,7 @@ var model = flag.String("model", "models/default.tflite", "Path to the model (pr
|
||||||
var scorer = flag.String("scorer", "models/default.scorer", "Path to the external scorer")
|
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 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")
|
var storage = flag.String("voice-storage", "", "Where to store the voices")
|
||||||
|
var orgfile = flag.String("org-file", "", "The target Orgfile")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -44,7 +45,7 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if *model == "" || *scorer == "" {
|
if *model == "" || *scorer == "" || *orgfile == "" {
|
||||||
// In case of error print error and print usage
|
// In case of error print error and print usage
|
||||||
// This can also be done by passing -h or --help flags
|
// This can also be done by passing -h or --help flags
|
||||||
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
|
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
|
||||||
|
@ -61,7 +62,7 @@ func main() {
|
||||||
*storage = filepath.Join(dir, ".orion", "storage")
|
*storage = filepath.Join(dir, ".orion", "storage")
|
||||||
}
|
}
|
||||||
|
|
||||||
bot, err := core.CreateBot(storage)
|
bot, err := core.CreateBot(orgfile, storage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -18,10 +18,10 @@ package core
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -38,6 +38,8 @@ type Bot struct {
|
||||||
Model *asticoqui.Model
|
Model *asticoqui.Model
|
||||||
ExtendedMetaData bool
|
ExtendedMetaData bool
|
||||||
MaxResults uint
|
MaxResults uint
|
||||||
|
OrgFile string
|
||||||
|
Format string
|
||||||
db *DB
|
db *DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +49,7 @@ type Entry struct {
|
||||||
Visited bool
|
Visited bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateBot(storage *string) (*Bot,error) {
|
func CreateBot(orgfile *string, storage *string) (*Bot, error) {
|
||||||
voiceStorage := filepath.Join(*storage, "voices")
|
voiceStorage := filepath.Join(*storage, "voices")
|
||||||
dbpath := filepath.Join(*storage, "db")
|
dbpath := filepath.Join(*storage, "db")
|
||||||
err := os.MkdirAll(voiceStorage, 0750)
|
err := os.MkdirAll(voiceStorage, 0750)
|
||||||
|
@ -68,7 +70,9 @@ func CreateBot(storage *string) (*Bot,error) {
|
||||||
ExtendedMetaData: false,
|
ExtendedMetaData: false,
|
||||||
StoragePath: *storage,
|
StoragePath: *storage,
|
||||||
VoiceStorage: voiceStorage,
|
VoiceStorage: voiceStorage,
|
||||||
|
OrgFile: *orgfile,
|
||||||
db: db,
|
db: db,
|
||||||
|
Format: "* %s\n:FILE:\npath:%s\nsize:%s\n:END:\n",
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,8 +129,27 @@ func (bot *Bot) StartBot() {
|
||||||
b.Start()
|
b.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *Bot) SaveTranscript(filepath *string, text *string) error {
|
func (bot *Bot) SaveTranscript(voicefilepath *string, text *string) error {
|
||||||
return ioutil.WriteFile(*filepath + ".txt", []byte(*text), 0600)
|
fi, err := os.Stat(*voicefilepath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
entry := fmt.Sprintf(bot.Format,
|
||||||
|
*text, *voicefilepath,
|
||||||
|
strconv.FormatInt(fi.Size(), 10))
|
||||||
|
|
||||||
|
f, err := os.OpenFile(bot.OrgFile, os.O_APPEND|os.O_WRONLY, 0600)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
if _, err = f.WriteString(entry); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *Bot) isOwner(c tele.Context) bool {
|
func (bot *Bot) isOwner(c tele.Context) bool {
|
||||||
|
@ -162,7 +185,6 @@ func (bot *Bot) StoreVoice(c tele.Context) (*string, error) {
|
||||||
return &wavePath, nil
|
return &wavePath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (bot *Bot) ConvertToText(voice *string) (*[]string, error) {
|
func (bot *Bot) ConvertToText(voice *string) (*[]string, error) {
|
||||||
// Stat audio
|
// Stat audio
|
||||||
i, err := os.Stat(*voice)
|
i, err := os.Stat(*voice)
|
||||||
|
@ -222,7 +244,6 @@ func (bot *Bot) ConvertToText(voice *string) (*[]string, error) {
|
||||||
return &results, nil
|
return &results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func metadataToStrings(m *asticoqui.Metadata) []string {
|
func metadataToStrings(m *asticoqui.Metadata) []string {
|
||||||
results := make([]string, 0, m.NumTranscripts())
|
results := make([]string, 0, m.NumTranscripts())
|
||||||
for _, tr := range m.Transcripts() {
|
for _, tr := range m.Transcripts() {
|
||||||
|
|
Loading…
Reference in New Issue