000x000 4942bb845d mod fix | пре 2 година | |
---|---|---|
test_data | пре 2 година | |
.travis.yml | пре 2 година | |
LICENSE | пре 2 година | |
README.md | пре 2 година | |
README.ru.md | пре 2 година | |
const.go | пре 2 година | |
go.mod | пре 2 година | |
go.sum | пре 2 година | |
stt.go | пре 2 година | |
tts.go | пре 2 година | |
yask.go | пре 2 година | |
z_test.go | пре 2 година |
English | Русский
Tools for work with the synthesis and speech recognition service Yandex Speech Kit (more about in https://cloud.yandex.ru/docs/speechkit/) for golang programming language. Used to synthesize speech from text and recognize text from a sound stream.
Before start to use, you must register at https://cloud.yandex.ru/ to get the API key and directory identifier (more about https://cloud.yandex.ru/docs).
As a result of the example, get a file in wav format, ready for playback in any player program. The default bitrate is 8000.
import ( "log" "os" "github.com/fcg-xvii/go-tools/speech/yask" ) func main() { yaFolderID := "b1g..." // yandex folder id yaAPIKey := "AQVNy..." // yandex api yandex text := "Hi It's test of speech synthesis" // text for synthesis // init config for synthesis (по умоланию установлен формат lpcm) config := yask.TTSDefaultConfigText(yaFolderID, yaAPIKey, text) // By default language in config russian. For english must setup // english language and voice config.Lang = yask.LangEN config.Voice = yask.VoiceNick // speech synthesis r, err := yask.TextToSpeech(config) if err != nil { log.Println(err) return } // open file for save result f, err := os.OpenFile("tts.wav", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0655) if err != nil { log.Println(err) return } defer f.Close() // lpcm encoding to wav format if err := yask.EncodePCMToWav(r, f, config.Rate, 16, 1); err != nil { log.Println(err) return } }
Example of recognition of short audio. The example uses a wav file that can be used with a configuration format value of lpcm
package main
import (
"log"
"os"
"github.com/fcg-xvii/go-tools/speech/yask"
)
func main() {
yaFolderID := "b1g4..." // yandex folder id
yaAPIKey := "AQVNyr..." // yandex api key
dataFileName := "data.wav" // audio file in wav format for recodnition to text
// open audio file
f, err := os.Open(dataFileName)
if err != nil {
log.Println(err)
return
}
defer f.Close()
// init config for recodnition
config := yask.STTConfigDefault(yaFolderID, yaAPIKey, f)
// setup english language
config.Lang = yask.LangEN
// recodnition speech to text
text, err := yask.SpeechToTextShort(config)
if err != nil {
log.Println(err)
return
}
log.Println(text)
}
The MIT License (MIT), see LICENSE.