tts2media

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2016 License: MIT Imports: 11 Imported by: 1

README

tts2media

Run TTS engines, convert their outputs (WAV files) to mp3 and ogg, and make videos from images or other videos. As used in http://nask.co.

Docs

See https://godoc.org/github.com/pqyptixa/tts2media for documentation.

Support

Only tested on Linux.

Dependencies

From Go: no external packages are needed. Tested with Go 1.5

System: Requires espeak, picotts (pico2wave) and ffmpeg + ffprobe.

Documentation

Overview

Package tts2media runs TTS engines, converts their output to mp3 and ogg (as audio files) and makes videos from images or other videos.

Files created by all functions and methods in this package are stored under the directory passed to SetDataDir(), and read from a subdirectory, named "tmp", that must be created under the same directory. If SetDataDir() isn't called, the media files will be saved in the current working directory.

saveDir, err := ioutil.TempDir(os.TempDir(), "")
...
err = os.Mkdir(saveDir+"tmp", 0700)
...
SetDataDir(saveDir)
...
espeak := &EspeakSpeech{
	Text:     "Hello World!",	// text to turn to speech
	Lang:     "en",			// language
	Speed:    "135",		// speed
	Gender:   "m",			// gender
	Altvoice: "0",			// alternative voice
	Quality:  "high",		// quality of output mp3/ogg audio
	Pitch:    "50",			// pitch
}

media, err := espeak.NewEspeakSpeech()
...
err = media.ToAudio()
...
media.RemoveWAV()

Other than RemoveWAV(), functions don't remove any files.

For the functions of this package that create videos, and unless specified otherwise, the filenames passed should be the same as the input audio files, and should not contain extensions.

Index

Constants

This section is empty.

Variables

View Source
var FilenameLen int = 10

FilenameLen: length of the string returned as filename for media files (mp3, ogg, mp4, webm)

Functions

func Duration

func Duration(path string) (string, error)

Duration returns the "Duration" from the format info

func FromVideo

func FromVideo(Audio string, lengthAsVideo bool) (string, error)

FromVideo creates videos from inputs video and Ogg audio files (previously generated by ToAudio). The last argument indicates the length, in seconds, of the output file: if lengthAsVideo is true, the length of the output file, in seconds, is the same as the input video. Otherwise, it is the same as the input audio. The output videos are stored with the same format (plus corresponding extensions) as input files. FromVideo checks if the (OGG) audio file exists, and detects the mime type of the input video.

func ImageToVideo

func ImageToVideo(Audio, imageExtension string) (string, error)

ImageToVideo creates two videos, encoded as MP4 and Webm, from the input files. Inputs are: an image file and an OGG audio file (previously generated by ToAudio). The filename of the input images should include the file extension. The output video is stored in dataPath, with formats (= extensions) webm and mp4. ImageToVideo checks if the (OGG) audio file exists.

func SetDataDir

func SetDataDir(dataDir string)

SetDataDir sets the directories where the media files are saved

func Type

func Type(path string) (string, error)

Function Type returns the MIME type of the media files, or an error if the file is not a jpg, gif, png, mp3, ogg, webm or mp4 file

Types

type EspeakSpeech

type EspeakSpeech struct {
	Text     string
	Lang     string
	Speed    string
	Gender   string
	Altvoice string
	Quality  string
	Pitch    string
}

EspeakSpeech: values needed to create wav files by calling the Espeak speech engine

Language: language of the speaker, aka "voice name" in espeak; values: "af", "bs", "ca", "cs", "cy", "de", "en", "en-sc", "en-uk", "en-uk-north", "en-uk-rp", "en-uk-wmids", "en-us", "en-wi", "eo", "es", "es-la", "fi", "fr", "fr-be", "grc", "hr", "hu", "id", "is", "it", "jbo", "ku", "la", "lv", "mk", "nl", "no", "pl", "pt-pt", "pt", "ro", "ru", "sk", "sq", "sr", "sv", "sw", "tr", "vi", "zh", "zh-yue", "hi", "el", "ta"

Speed: speed in words per minute; values: from "80" to "390"

Gender: gender of the speaker; values: "m" for male, and "f" for female. note: not all voices support different genders

Altvoice: alternative voice; values: from "0" to "5"

Quality: quality of the output MP3/OGG audio; values: "high", "medium" or "low"

Pitch: pitch adjustment; values: from "0" to "99"

func (*EspeakSpeech) NewEspeakSpeech

func (s *EspeakSpeech) NewEspeakSpeech() (*Media, error)

NewEspeakSpeech creates (after validating inputs) a WAV file with a random filename If the operation succeeds, it returns the filename (without path or extension) and a nil error. Otherwise, returns an empty string and an error

type Media

type Media struct {
	Filename   string
	BitRate    string
	SampleRate string
}

Media: values needed to create media (mp3, ogg, mp4, webm) files generated by the speech engines

func (*Media) ImageToVideo

func (m *Media) ImageToVideo(imageExtension string) (string, error)

ImageToVideo creates Webm and MP4 files from the file specified as the first argument and the ogg file generated by ToAudio()

func (*Media) RemoveWAV

func (m *Media) RemoveWAV() error

RemoveWAV deletes the WAV file generated by the speech engines

func (*Media) ToAudio

func (m *Media) ToAudio() error

ToAudio creates mp3 and ogg files from the wav file generated by NewEspeakSpeech, NewPicoTTSSpeech or NewFestivalSpeech

type PicoTTSSpeech

type PicoTTSSpeech struct {
	Text    string
	Lang    string
	Quality string
}

PicoTTSSpeech: values needed to create wav files by calling the PicoTTS speech engine

func (*PicoTTSSpeech) NewPicoTTSSpeech

func (s *PicoTTSSpeech) NewPicoTTSSpeech() (*Media, error)

NewPicoTTSSpeech creates (after validating inputs) a WAV file with a random filename. If the operation succeeds, it returns the filename (without path or extension) and a nil error. Otherwise, returns an empty string and an error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL