From 72bab91153530a9de24e606821d0261a2d8440cb Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Mon, 5 Sep 2022 16:09:06 +0100 Subject: [PATCH] migrating to miniblack --- rigel/tcp.py | 2 +- env.example => telegram_bot/env.example | 0 go.mod => telegram_bot/go.mod | 0 go.sum => telegram_bot/go.sum | 0 orion.go => telegram_bot/orion.go | 0 telegram_bot/pkg/core/#converter.go# | 185 ++++++++++++++++++++ {pkg => telegram_bot/pkg}/core/converter.go | 0 {pkg => telegram_bot/pkg}/core/core.go | 0 {pkg => telegram_bot/pkg}/core/db.go | 0 9 files changed, 186 insertions(+), 1 deletion(-) rename env.example => telegram_bot/env.example (100%) rename go.mod => telegram_bot/go.mod (100%) rename go.sum => telegram_bot/go.sum (100%) rename orion.go => telegram_bot/orion.go (100%) create mode 100644 telegram_bot/pkg/core/#converter.go# rename {pkg => telegram_bot/pkg}/core/converter.go (100%) rename {pkg => telegram_bot/pkg}/core/core.go (100%) rename {pkg => telegram_bot/pkg}/core/db.go (100%) diff --git a/rigel/tcp.py b/rigel/tcp.py index dce3844..366d28f 100644 --- a/rigel/tcp.py +++ b/rigel/tcp.py @@ -85,7 +85,7 @@ def synth(config): break wav = synthesizer.tts(message, speaker_idx, "None", None) - # synthesizer.save_wav(wav, "/tmp/blah.wav") + synthesizer.save_wav(wav, "/tmp/blah.wav") play(wav) writer.write(b"Ok") diff --git a/env.example b/telegram_bot/env.example similarity index 100% rename from env.example rename to telegram_bot/env.example diff --git a/go.mod b/telegram_bot/go.mod similarity index 100% rename from go.mod rename to telegram_bot/go.mod diff --git a/go.sum b/telegram_bot/go.sum similarity index 100% rename from go.sum rename to telegram_bot/go.sum diff --git a/orion.go b/telegram_bot/orion.go similarity index 100% rename from orion.go rename to telegram_bot/orion.go diff --git a/telegram_bot/pkg/core/#converter.go# b/telegram_bot/pkg/core/#converter.go# new file mode 100644 index 0000000..0ef9b00 --- /dev/null +++ b/telegram_bot/pkg/core/#converter.go# @@ -0,0 +1,185 @@ +/* + Orion --- Speech to text bot + + Copyright (c) 2022 Sameer Rahmani + + 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 . +*/ + +package core + +import ( + "os/exec" +) + +func ConvertOggtoWav(inputFile *string, outputFile *string) error { + cmd := exec.Command("ffmpeg", "-i", *inputFile, "-ar", "16000", *outputFile) + if err := cmd.Run(); err != nil { + return err + } + return nil +} + +// ============================= +// Since sox doesn't support Opus and telegram uses opus format, i've +// tried to convert opus to wav but it didn't go well and since it's +// a personal project and I don't want to spend much time on it, I've +// decided to use ffmpeg but I'm keeping my effort here. Maybe in the +// future I spend more time on it. + +// func ConvertOpusToWav(inputFile *string, outputFile *string) error { +// channels := 1 + +// f, err := os.Open(*inputFile) +// if err != nil { +// return err +// } +// defer f.Close() + +// wavOut, err := os.Create(*outputFile) + +// if err != nil { +// return err +// } +// defer wavOut.Close() + +// out := wav.File{ +// Channels: 1, +// SampleRate: rate, +// SignificantBits: bits, +// } +// writer, err := out.NewWriter(wavOut) +// if err != nil { +// return err +// } +// defer writer.Close() + +// s, err := opus.NewStream(f) +// if err != nil { +// return err +// } +// defer s.Close() + +// pcmbuf := make([]int16, ) +// for { +// n, err := s.Read(pcmbuf) +// if err == io.EOF { +// break +// } else if err != nil { +// return err +// } + +// pcm := pcmbuf[:n*channels] +// buf := new(bytes.Buffer) +// err = binary.Write(buf, binary.LittleEndian, pcm) +// if err != nil { +// return err +// } + +// writer.WriteSample(buf.Bytes()) +// // send pcm to audio device here, or write to a .wav file +// } +// return nil +// // sampleRate := 16000 +// // frameSizeMs := 60 +// // frameSize := channels * frameSizeMs * sampleRate / 1000 + +// // dec, err := opus.NewDecoder(sampleRate, channels) + +// // if err != nil { +// // return nil, err +// // } + +// // in, err := os.Open(*inputFile) +// // if err != nil { +// // return nil, err +// // } +// // defer in.Close() +// // data, err := ioutil.ReadFile(*inputFile) + +// // if err != nil { +// // return nil, err +// // } + +// // pcm := make([]int16, int(frameSize)) +// // n, err := dec.Decode(data, pcm) +// // if err != nil { +// // return nil, err +// // } + +// // // To get all samples (interleaved if multiple channels): +// // pcm = pcm[:n*channels] // only necessary if you didn't know the right frame size +// // return pcm, nil +// // // buf := new(bytes.Buffer) +// // // err = binary.Write(buf, binary.LittleEndian, pcm) +// // // if(err != nil) { +// // // return nil, err +// // // } +// // // return buf.Bytes(), nil +// } + +// func ConvertToWav(inputFile *string, outputFile *string) error { +// if !sox.Init() { +// return fmt.Errorf("failed to initialize SoX") +// } +// defer sox.Quit() + +// // Open the input file (with default parameters) +// in := sox.OpenRead(*inputFile) +// if in == nil { +// return fmt.Errorf("failed to open input ogg file") +// } +// // Close the file before exiting +// defer in.Release() + +// out := sox.OpenWrite(*outputFile, in.Signal(), nil, "alsa") +// if out == nil { +// out = sox.OpenWrite("default", in.Signal(), nil, "pulseaudio") +// if out == nil { +// return fmt.Errorf("failed to open output device") +// } +// } +// // Close the output device before exiting +// defer out.Release() + +// // Create an effects chain: Some effects need to know about the +// // input or output encoding so we provide that information here. +// chain := sox.CreateEffectsChain(in.Encoding(), out.Encoding()) +// // Make sure to clean up! +// defer chain.Release() + +// // The first effect in the effect chain must be something that can +// // source samples; in this case, we use the built-in handler that +// // inputs data from an audio file. +// e := sox.CreateEffect(sox.FindEffect("input")) +// e.Options(in) +// // This becomes the first "effect" in the chain +// chain.Add(e, in.Signal(), in.Signal()) +// e.Release() + +// // Create the `rate' effect, to set the samplerate +// e = sox.CreateEffect(sox.FindEffect("rate")) +// e.Options(16000) +// chain.Add(e, in.Signal(), in.Signal()) +// e.Release() + +// // The last effect in the effect chain must be something that only consumes +// // samples; in this case, we use the built-in handler that outputs data. +// e = sox.CreateEffect(sox.FindEffect("output")) +// e.Options(out) +// chain.Add(e, in.Signal(), in.Signal()) +// e.Release() + +// // Flow samples through the effects processing chain until EOF is reached. +// chain.Flow() + +// return nil +// } // diff --git a/pkg/core/converter.go b/telegram_bot/pkg/core/converter.go similarity index 100% rename from pkg/core/converter.go rename to telegram_bot/pkg/core/converter.go diff --git a/pkg/core/core.go b/telegram_bot/pkg/core/core.go similarity index 100% rename from pkg/core/core.go rename to telegram_bot/pkg/core/core.go diff --git a/pkg/core/db.go b/telegram_bot/pkg/core/db.go similarity index 100% rename from pkg/core/db.go rename to telegram_bot/pkg/core/db.go