<commit_before>// Package pulseaudio implements playing audio using native protocol.
// It implements just enough of the protocol and nothing else.
package pulseaudio

import (
  "bytes"
  "context"
  "encoding/binary"
  "io"
  "io/ioutil"
)

// Play plays an audio stream on a PulseAudio server.
// Format is float32 little-endian, stereo, sampling 44100 Hz.
func Play(ctx context.Context, server io.ReadWriter, stream io.Reader) error {
  if err := pulseAuth(server); err != nil {
    return err
  }
  if err := pulseCreatePlaybackStream(server); err != nil {
    return err
  }
  go io.Copy(ioutil.Discard, server) // ignore the server

  b := make([]byte, 4096)
  for {
    select {
    case <-ctx.Done():
      return nil
    default:
    }
    n, err := stream.Read(b)
    if err != nil {
      return err
    }
    if err := pulseWritePacket(server, 0, b[:n]); err != nil {
      return err
    }
  }
  return nil
}

func pulseWritePacket(w io.Writer, index uint32, data []byte) error {
  b := &bytes.Buffer{}
  binary.Write(b, binary.BigEndian, uint32(len(data))) // length
  binary.Write(b, binary.BigEndian, uint32(index))     // index<commit_msg>pulseaudio: remove unnecessary return, go sees loop<commit_after>// Package pulseaudio implements playing audio using native protocol.
// It implements just enough of the protocol and nothing else.
package pulseaudio

import (
  "bytes"
  "context"
  "encoding/binary"
  "io"
  "io/ioutil"
)

// Play plays an audio stream on a PulseAudio server.
// Format is float32 little-endian, stereo, sampling 44100 Hz.
func Play(ctx context.Context, server io.ReadWriter, stream io.Reader) error {
  if err := pulseAuth(server); err != nil {
    return err
  }
  if err := pulseCreatePlaybackStream(server); err != nil {
    return err
  }
  go io.Copy(ioutil.Discard, server) // ignore the server

  b := make([]byte, 4096)
  for {
    select {
    case <-ctx.Done():
      return nil
    default:
    }
    n, err := stream.Read(b)
    if err != nil {
      return err
    }
    if err := pulseWritePacket(server, 0, b[:n]); err != nil {
      return err
    }
  }
}

func pulseWritePacket(w io.Writer, index uint32, data []byte) error {
  b := &bytes.Buffer{}
  binary.Write(b, binary.BigEndian, uint32(len(data))) // length
  binary.Write(b, binary.BigEndian, uint32(index))     // index
{'fraction_non_alphanumeric': 0.12398460880718255, 'fraction_numerical': 0.015391192817443352, 'mean_word_length': 3.013722126929674, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6393314', 'n_tokens_mistral': 779, 'n_tokens_neox': 745, 'n_words': 241}