Skip to content

Instantly share code, notes, and snippets.

@nogweii
Last active September 21, 2015 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nogweii/45f2b2fcaf2699818fea to your computer and use it in GitHub Desktop.
Save nogweii/45f2b2fcaf2699818fea to your computer and use it in GitHub Desktop.
mumble razzle hatbot play whole function
module Mumble
class Client
def conn
@conn
end
def config
@config
end
end
end
class MyAudioPlayer < Mumble::AudioPlayer
attr_reader :queue, :file
attr_accessor :playing
public :consume
def bounded_encode
@file.each_buffer(@encoder.frame_size) do |buffer|
puts "Encoding #{buffer.samples.size} samples as OPUS..."
encode_sample buffer.samples.pack('s*')
end
end
def read_wav(file)
puts "Reading wav #{file} as a #{@wav_format}."
@file = WaveFile::Reader.new(file, @wav_format)
end
end
@audio_streamer = MyAudioPlayer.new Mumble::Client::CODEC_OPUS,
$client.conn,
$client.config.sample_rate,
$client.config.bitrate
def play_whole_file(wav_path)
unless @audio_streamer.playing?
@audio_streamer.playing = true
@audio_streamer.read_wav(wav_path)
@audio_streamer.bounded_encode
while !@audio_streamer.queue.empty?
puts "Consuming part of the audio queue..."
@audio_streamer.consume
end
@audio_streamer.stop
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment