func NewSession(callback Callback) *Session { ctx, cancel := context.WithCancel(context.Background()) g, ctx := errgroup.WithContext(ctx) // 关键:绑定 context s := &Session{ ctx: ctx, cancel: cancel, g: g, bus: eventbus.NewBus(1024), output: make(chan SessionMessage, 32), ttsEnabled: false, consumers: make(map[SessionName]*Consumer), callback: callback, } // go s.runPipeline() return s }
func (b *Bus) Subscribe(ctx context.Context, types ...EventType) (*Subscriber, func()) { ctx, cancel := context.WithCancel(ctx) g, ctx := errgroup.WithContext(ctx) ....
for { select { case <-ctx.Done(): syn.conn.Close() log.Println("Context done, exiting tts warp readLoop.") return nil case message, ok := <-l.ch: if !ok { log.Println("TTSStream event channel closed") return nil }
func (s *SpeechSynthesizer) readLoop() error { defer func() { close(s.closed) log.Println("SpeechSynthesizer readLoop exited") }() for { if s.conn == nil { return nil }
Github开源生信云平台 DEMO