mirror of
https://github.com/litruv/PNGTuber-Plus.git
synced 2026-07-24 02:26:02 +10:00
Integrate microphone improvements from k0ffinz repository
- Add experimental microphone loudness detection feature - Remove microphone restart interval for better stability - Improve microphone initialization and error handling - Fix audio delay issues by setting channel_disable_time=0.0 - Update settings UI to include experimental mic loudness toggle - Add credits to k0ffinz/Ralsi for microphone improvements These changes improve audio responsiveness and fix various microphone-related issues including WASAPI errors and growing audio delay problems.
This commit is contained in:
@@ -14,3 +14,4 @@
|
||||
- **Original Project**: PNGTuber Plus base application
|
||||
- **StreamDeck Plugin**: Based on [BoyneGames StreamDeck Godot Plugin](https://github.com/BoyneGames/streamdeck-godot-plugin)
|
||||
- **Enhanced Features**: Max Litruv Boonzaayer
|
||||
- **Microphone Improvements**: k0ffinz/Ralsi - Experimental mic loudness detection, improved audio initialization, and audio delay fixes from [k0ffinz/PNGTuber-Plus](https://github.com/k0ffinz/PNGTuber-Plus)
|
||||
|
||||
@@ -29,13 +29,13 @@ var blink = false
|
||||
var blinkTick = 0
|
||||
|
||||
#Audio Listener
|
||||
|
||||
var currentMicrophone = null
|
||||
var playa:AudioStreamPlayer
|
||||
|
||||
var speaking = false
|
||||
var spectrum
|
||||
var volume = 0
|
||||
var volumeSensitivity = 0.0
|
||||
var experimentalMicLoudness = false
|
||||
|
||||
var volumeLimit = 0.0
|
||||
var senseLimit = 0.0
|
||||
@@ -44,8 +44,6 @@ var senseLimit = 0.0
|
||||
signal startSpeaking
|
||||
signal stopSpeaking
|
||||
|
||||
var micResetTime = 180
|
||||
|
||||
var updatePusherNode = null
|
||||
|
||||
var rand = RandomNumberGenerator.new()
|
||||
@@ -56,28 +54,23 @@ func _ready():
|
||||
if !Saving.settings.has("useStreamDeck"):
|
||||
Saving.settings["useStreamDeck"] = false
|
||||
|
||||
if Saving.settings.has("secondsToMicReset"):
|
||||
Global.micResetTime = Saving.settings["secondsToMicReset"]
|
||||
if Saving.settings.has("experimentalMicLoudness"):
|
||||
Global.experimentalMicLoudness = Saving.settings["experimentalMicLoudness"]
|
||||
else:
|
||||
Saving.settings["secondsToMicReset"] = 180
|
||||
|
||||
Saving.settings["experimentalMicLoudness"] = false
|
||||
|
||||
createMicrophone()
|
||||
|
||||
func createMicrophone():
|
||||
var playa = AudioStreamPlayer.new()
|
||||
var mic = AudioStreamMicrophone.new()
|
||||
playa.stream = mic
|
||||
playa.autoplay = true
|
||||
if playa != null:
|
||||
remove_child(playa)
|
||||
playa.free()
|
||||
playa = AudioStreamPlayer.new()
|
||||
playa.bus = "MIC"
|
||||
playa.stream = AudioStreamMicrophone.new()
|
||||
add_child(playa)
|
||||
currentMicrophone = playa
|
||||
await get_tree().create_timer(micResetTime).timeout
|
||||
if currentMicrophone != playa:
|
||||
return
|
||||
deleteAllMics()
|
||||
currentMicrophone = null
|
||||
await get_tree().create_timer(0.25).timeout
|
||||
createMicrophone()
|
||||
await get_tree().create_timer(0.25).timeout # apparently it works to fix WASAPI "Initialize failed with error 0xffffffff88890002" and "init_input_device" errors
|
||||
playa.play()
|
||||
|
||||
func deleteAllMics():
|
||||
for child in get_children():
|
||||
@@ -87,8 +80,9 @@ func deleteAllMics():
|
||||
func _process(delta):
|
||||
animationTick += 1
|
||||
|
||||
volume = spectrum.get_magnitude_for_frequency_range(20, 20000).length()
|
||||
if currentMicrophone != null:
|
||||
volume = (AudioServer.get_bus_peak_volume_left_db(1, 0) + AudioServer.get_bus_peak_volume_right_db(1, 0)) / 1600.0 + 0.25 if experimentalMicLoudness else spectrum.get_magnitude_for_frequency_range(20, 20000).length()
|
||||
|
||||
if playa != null:
|
||||
volumeSensitivity = lerp(volumeSensitivity,0.0,delta*2)
|
||||
|
||||
if volume>volumeLimit:
|
||||
|
||||
@@ -54,13 +54,13 @@ var settings = {
|
||||
"bounce":250,
|
||||
"gravity":1000,
|
||||
"maxFPS":60,
|
||||
"secondsToMicReset":180,
|
||||
"backgroundColor":var_to_str(Color(0.0,0.0,0.0,0.0)),
|
||||
"filtering":false,
|
||||
"costumeKeys":["1","2","3","4","5","6","7","8","9","0"],
|
||||
"blinkSpeed":1.0,
|
||||
"blinkChance":200,
|
||||
"bounceOnCostumeChange":false,
|
||||
"experimentalMicLoudness":false,
|
||||
}
|
||||
|
||||
var settingsPath = "user://settings.pngtp"
|
||||
|
||||
@@ -23,6 +23,7 @@ config/icon="res://icon.png"
|
||||
[audio]
|
||||
|
||||
driver/enable_input=true
|
||||
buses/channel_disable_time=0.0
|
||||
|
||||
[autoload]
|
||||
|
||||
|
||||
@@ -7,17 +7,11 @@ func _ready():
|
||||
|
||||
|
||||
func _on_button_pressed():
|
||||
|
||||
if !get_parent().get_parent().get_parent().visible:
|
||||
return
|
||||
|
||||
AudioServer.input_device = micName
|
||||
Global.deleteAllMics()
|
||||
Global.currentMicrophone = null
|
||||
|
||||
Global.createMicrophone()
|
||||
get_parent().get_parent().get_parent().visible = false
|
||||
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
Global.createMicrophone()
|
||||
|
||||
|
||||
|
||||
@@ -46,6 +46,8 @@ func setvalues():
|
||||
label.text = "costume " + str(tag) + " key: \"" + Global.main.costumeKeys[tag-1] + "\""
|
||||
tag += 1
|
||||
|
||||
$experimentalMicLoudness/checkmark.button_pressed = Global.experimentalMicLoudness
|
||||
|
||||
func _on_color_picker_button_color_changed(color):
|
||||
get_viewport().transparent_bg = false
|
||||
RenderingServer.set_default_clear_color(color)
|
||||
@@ -206,6 +208,12 @@ func _on_stream_deck_check_toggled(button_pressed):
|
||||
get_node("/root/ElgatoStreamDeck").refresh_connection()
|
||||
Global.pushUpdate("StreamDeck integration " + ("enabled" if button_pressed else "disabled") + ".")
|
||||
|
||||
## Handle experimental microphone loudness toggle
|
||||
## @param checked: bool - Whether experimental mic loudness should be enabled
|
||||
func _on_experimental_mic_loudness_toggle(checked):
|
||||
Global.experimentalMicLoudness = checked
|
||||
Saving.settings["experimentalMicLoudness"] = checked
|
||||
|
||||
|
||||
func _process(delta):
|
||||
var g = to_local(get_global_mouse_position())
|
||||
|
||||
Reference in New Issue
Block a user