Yandex Speech Kit client

000x000 4942bb845d mod fix пре 2 година
test_data 4c9185e60f First пре 2 година
.travis.yml 4c9185e60f First пре 2 година
LICENSE 4c9185e60f First пре 2 година
README.md 4c9185e60f First пре 2 година
README.ru.md 4c9185e60f First пре 2 година
const.go 4c9185e60f First пре 2 година
go.mod 4942bb845d mod fix пре 2 година
go.sum 4942bb845d mod fix пре 2 година
stt.go 4c9185e60f First пре 2 година
tts.go 4c9185e60f First пре 2 година
yask.go 4c9185e60f First пре 2 година
z_test.go 4942bb845d mod fix пре 2 година

README.md

English | Русский

Build Status Go Report Card

yask

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).

Audio stream formats

Speech synthesis from text

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
	}
}

Speech recognition to text

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)
}

License

The MIT License (MIT), see LICENSE.