Coder Social home page Coder Social logo

Comments (10)

bkacjios avatar bkacjios commented on August 23, 2024 1

You could always calculate the delay between each packet by doing something like this.

client:hook("OnUserStartSpeaking", function(client, user)
	user.last_spoke = mumble.gettime()
end)

client:hook("OnUserSpeak", function(client, event)
	local t = mumble.gettime()

	local user = event.user

	-- Round to nearest tenth
	local delay = math.floor((t - user.last_spoke) * 100 + 0.5) / 100
	-- delay = time between each packet

	user.speech_delay = delay
	user.last_spoke = t
end)

client:hook("OnUserStopSpeaking", function(client, user)
	print("User spoke with a delay of", user.speech_delay)
end)

from lua-mumble.

bkacjios avatar bkacjios commented on August 23, 2024 1

Hey, so I also just pushed a commit to fix a bug where OnUserStartSpeaking and OnUserStopSpeaking could potentially not be called if the user only sent 1 frame of audio data. This can happen if a user presses their push to talk button really fast.

Also, for calculating the delay, it may be better to use the highest delay value during the transmission.

client:hook("OnUserStartSpeaking", function(client, user)
	user.last_spoke = mumble.gettime()
	user.speech_delay = 0
end)

client:hook("OnUserSpeak", function(client, event)
	local t = mumble.gettime()

	local user = event.user

	-- Round to nearest tenth
	local delay = math.floor((t - user.last_spoke) * 100 + 0.5) / 100
	-- delay = time between each packet

	if delay > user.speech_delay then
		-- Only update the delay value when it's higher than the last value
		user.speech_delay
	end

	user.last_spoke = t
end)

client:hook("OnUserStopSpeaking", function(client, user)
	print("User spoke with a delay of", user.speech_delay)
end)

I found that sometimes the delay can be sometimes be low on the last transmitted frame, which is perfectly fine, but could cause your value to be lower than it should.

from lua-mumble.

bkacjios avatar bkacjios commented on August 23, 2024

There's not a real easy way to do this. The client just accepts the voice packets as they come, so it doesn't actually know the rate in which they are received.

from lua-mumble.

hbeni avatar hbeni commented on August 23, 2024

Very recently, in the plugins WIP branch, an addition was made that exposes this information:
mumble-voip/mumble@41244d7

So, somewhere it must be hidden... Sorry that i have not much more information :(

from lua-mumble.

bkacjios avatar bkacjios commented on August 23, 2024

Sample rate is not the same as the time between each packet. Sample rate is the quality of the audio.

Actually I'm dumb. I haven't been messing with this mumble stuff for a bit. Even still, there's no way for me to tell what the sample rate is just from the voice packets it receives alone. There has to be more to that commit you linked, because the information has to come from somewhere.

from lua-mumble.

bkacjios avatar bkacjios commented on August 23, 2024

From what I can tell, they end up passing SAMPLE_RATE define to those calls, which is defined as 48000, so I don't think that value even helps you here either.

https://github.com/mumble-voip/mumble/blob/41244d7df41651876033e227d8ef625bf38ca839/src/mumble/AudioOutput.cpp#L530
https://github.com/mumble-voip/mumble/blob/3d7f8cc4e5f502652f6660822eb791cec79a61f7/src/mumble/Audio.h#L18

from lua-mumble.

hbeni avatar hbeni commented on August 23, 2024

so I don't think that value even helps you here either.

I hoped there would be some magic formula to calculate the spacing... and unfortunately, i have no clue about PCM and audio sampling :(

from lua-mumble.

hbeni avatar hbeni commented on August 23, 2024

I will try that soon, thank you very much!

from lua-mumble.

hbeni avatar hbeni commented on August 23, 2024

Cool, thanks!!!

from lua-mumble.

hbeni avatar hbeni commented on August 23, 2024

Just for the archives, it works.

I however record all seen delays into an array and then take the average from that to smooth out possible excess values. The result gets rounded to the nearest tenth like coded above. That seems to work very reliably.

https://github.com/hbeni/fgcom-mumble/blob/d779699b3a81ec712ea2d23e7507fbcc6e858c2e/server/fgcom-radio-recorder.bot.lua#L312

        -- record timings between voice packets to determine the sampling speed
        local time  = mumble.getTime()
        local delay = time - (remote.last_spoke or time)
        remote.last_spoke = time
        if delay > 0 then
            if not remote.record_delay then
                remote.record_delay = {delay}
            else
                remote.record_delay[#(remote.record_delay)+1] = delay
            end
        end

https://github.com/hbeni/fgcom-mumble/blob/d779699b3a81ec712ea2d23e7507fbcc6e858c2e/server/fgcom-radio-recorder.bot.lua#L388

                -- calculate the packet speed
                local calculated_packet_speed = 0.02   -- mumbles default setting
                if #(remote.record_delay) > 0 then
                    calculated_packet_speed       = math.average(remote.record_delay)
                    calculated_packet_speed       = math.floor(calculated_packet_speed * 100 + 0.5) / 100   -- round to nearest tenth
                end
                fgcom.dbg("calculated packet per audio: "..calculated_packet_speed)

from lua-mumble.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.