Exemple #1
0
func (p *Plugin) apiAudioPlay(tbl *lua.LTable) bool {
	if p.instance.Audio.IsPlaying() {
		return false
	}

	filename := tbl.RawGetH(lua.LString("filename"))

	exec := tbl.RawGetH(lua.LString("exec"))
	args := tbl.RawGetH(lua.LString("args"))

	callback := tbl.RawGetH(lua.LString("callback"))

	if enc, ok := p.instance.Client.AudioEncoder.(*opus.Encoder); ok {
		enc.SetApplication(gopus.Audio)
	}

	switch {
	// source file
	case filename != lua.LNil && exec == lua.LNil && args == lua.LNil:
		p.instance.Audio.Source = gumble_ffmpeg.SourceFile(filename.String())
	// source exec
	case filename == lua.LNil && exec != lua.LNil:
		var argsStr []string
		if argsTable, ok := args.(*lua.LTable); ok {
			for i := 1; ; i++ {
				arg := argsTable.RawGetInt(i)
				if arg == lua.LNil {
					break
				}
				argsStr = append(argsStr, arg.String())
			}
		}
		p.instance.Audio.Source = gumble_ffmpeg.SourceExec(exec.String(), argsStr...)
	default:
		panic("invalid source type")
	}

	p.instance.Audio.Play()
	go func() {
		p.instance.Audio.Wait()
		if callback.Type() != lua.LTNil {
			p.callValue(callback)
		}
	}()

	return true
}
Exemple #2
0
func (a *adapter) getTTSSource(str string) (gumble_ffmpeg.Source, error) {
	return gumble_ffmpeg.SourceExec("picospeaker", "--type", "wav", "--output", "-", str), nil
	//return &festivalSource{str: str}, nil
}