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
|
- **Original Project**: PNGTuber Plus base application
|
||||||
- **StreamDeck Plugin**: Based on [BoyneGames StreamDeck Godot Plugin](https://github.com/BoyneGames/streamdeck-godot-plugin)
|
- **StreamDeck Plugin**: Based on [BoyneGames StreamDeck Godot Plugin](https://github.com/BoyneGames/streamdeck-godot-plugin)
|
||||||
- **Enhanced Features**: Max Litruv Boonzaayer
|
- **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
|
var blinkTick = 0
|
||||||
|
|
||||||
#Audio Listener
|
#Audio Listener
|
||||||
|
var playa:AudioStreamPlayer
|
||||||
var currentMicrophone = null
|
|
||||||
|
|
||||||
var speaking = false
|
var speaking = false
|
||||||
var spectrum
|
var spectrum
|
||||||
var volume = 0
|
var volume = 0
|
||||||
var volumeSensitivity = 0.0
|
var volumeSensitivity = 0.0
|
||||||
|
var experimentalMicLoudness = false
|
||||||
|
|
||||||
var volumeLimit = 0.0
|
var volumeLimit = 0.0
|
||||||
var senseLimit = 0.0
|
var senseLimit = 0.0
|
||||||
@@ -44,8 +44,6 @@ var senseLimit = 0.0
|
|||||||
signal startSpeaking
|
signal startSpeaking
|
||||||
signal stopSpeaking
|
signal stopSpeaking
|
||||||
|
|
||||||
var micResetTime = 180
|
|
||||||
|
|
||||||
var updatePusherNode = null
|
var updatePusherNode = null
|
||||||
|
|
||||||
var rand = RandomNumberGenerator.new()
|
var rand = RandomNumberGenerator.new()
|
||||||
@@ -56,28 +54,23 @@ func _ready():
|
|||||||
if !Saving.settings.has("useStreamDeck"):
|
if !Saving.settings.has("useStreamDeck"):
|
||||||
Saving.settings["useStreamDeck"] = false
|
Saving.settings["useStreamDeck"] = false
|
||||||
|
|
||||||
if Saving.settings.has("secondsToMicReset"):
|
if Saving.settings.has("experimentalMicLoudness"):
|
||||||
Global.micResetTime = Saving.settings["secondsToMicReset"]
|
Global.experimentalMicLoudness = Saving.settings["experimentalMicLoudness"]
|
||||||
else:
|
else:
|
||||||
Saving.settings["secondsToMicReset"] = 180
|
Saving.settings["experimentalMicLoudness"] = false
|
||||||
|
|
||||||
createMicrophone()
|
createMicrophone()
|
||||||
|
|
||||||
func createMicrophone():
|
func createMicrophone():
|
||||||
var playa = AudioStreamPlayer.new()
|
if playa != null:
|
||||||
var mic = AudioStreamMicrophone.new()
|
remove_child(playa)
|
||||||
playa.stream = mic
|
playa.free()
|
||||||
playa.autoplay = true
|
playa = AudioStreamPlayer.new()
|
||||||
playa.bus = "MIC"
|
playa.bus = "MIC"
|
||||||
|
playa.stream = AudioStreamMicrophone.new()
|
||||||
add_child(playa)
|
add_child(playa)
|
||||||
currentMicrophone = playa
|
await get_tree().create_timer(0.25).timeout # apparently it works to fix WASAPI "Initialize failed with error 0xffffffff88890002" and "init_input_device" errors
|
||||||
await get_tree().create_timer(micResetTime).timeout
|
playa.play()
|
||||||
if currentMicrophone != playa:
|
|
||||||
return
|
|
||||||
deleteAllMics()
|
|
||||||
currentMicrophone = null
|
|
||||||
await get_tree().create_timer(0.25).timeout
|
|
||||||
createMicrophone()
|
|
||||||
|
|
||||||
func deleteAllMics():
|
func deleteAllMics():
|
||||||
for child in get_children():
|
for child in get_children():
|
||||||
@@ -87,8 +80,9 @@ func deleteAllMics():
|
|||||||
func _process(delta):
|
func _process(delta):
|
||||||
animationTick += 1
|
animationTick += 1
|
||||||
|
|
||||||
volume = spectrum.get_magnitude_for_frequency_range(20, 20000).length()
|
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 currentMicrophone != null:
|
|
||||||
|
if playa != null:
|
||||||
volumeSensitivity = lerp(volumeSensitivity,0.0,delta*2)
|
volumeSensitivity = lerp(volumeSensitivity,0.0,delta*2)
|
||||||
|
|
||||||
if volume>volumeLimit:
|
if volume>volumeLimit:
|
||||||
|
|||||||
@@ -54,13 +54,13 @@ var settings = {
|
|||||||
"bounce":250,
|
"bounce":250,
|
||||||
"gravity":1000,
|
"gravity":1000,
|
||||||
"maxFPS":60,
|
"maxFPS":60,
|
||||||
"secondsToMicReset":180,
|
|
||||||
"backgroundColor":var_to_str(Color(0.0,0.0,0.0,0.0)),
|
"backgroundColor":var_to_str(Color(0.0,0.0,0.0,0.0)),
|
||||||
"filtering":false,
|
"filtering":false,
|
||||||
"costumeKeys":["1","2","3","4","5","6","7","8","9","0"],
|
"costumeKeys":["1","2","3","4","5","6","7","8","9","0"],
|
||||||
"blinkSpeed":1.0,
|
"blinkSpeed":1.0,
|
||||||
"blinkChance":200,
|
"blinkChance":200,
|
||||||
"bounceOnCostumeChange":false,
|
"bounceOnCostumeChange":false,
|
||||||
|
"experimentalMicLoudness":false,
|
||||||
}
|
}
|
||||||
|
|
||||||
var settingsPath = "user://settings.pngtp"
|
var settingsPath = "user://settings.pngtp"
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ config/icon="res://icon.png"
|
|||||||
[audio]
|
[audio]
|
||||||
|
|
||||||
driver/enable_input=true
|
driver/enable_input=true
|
||||||
|
buses/channel_disable_time=0.0
|
||||||
|
|
||||||
[autoload]
|
[autoload]
|
||||||
|
|
||||||
|
|||||||
@@ -7,17 +7,11 @@ func _ready():
|
|||||||
|
|
||||||
|
|
||||||
func _on_button_pressed():
|
func _on_button_pressed():
|
||||||
|
|
||||||
if !get_parent().get_parent().get_parent().visible:
|
if !get_parent().get_parent().get_parent().visible:
|
||||||
return
|
return
|
||||||
|
|
||||||
AudioServer.input_device = micName
|
AudioServer.input_device = micName
|
||||||
Global.deleteAllMics()
|
Global.createMicrophone()
|
||||||
Global.currentMicrophone = null
|
|
||||||
|
|
||||||
get_parent().get_parent().get_parent().visible = false
|
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] + "\""
|
label.text = "costume " + str(tag) + " key: \"" + Global.main.costumeKeys[tag-1] + "\""
|
||||||
tag += 1
|
tag += 1
|
||||||
|
|
||||||
|
$experimentalMicLoudness/checkmark.button_pressed = Global.experimentalMicLoudness
|
||||||
|
|
||||||
func _on_color_picker_button_color_changed(color):
|
func _on_color_picker_button_color_changed(color):
|
||||||
get_viewport().transparent_bg = false
|
get_viewport().transparent_bg = false
|
||||||
RenderingServer.set_default_clear_color(color)
|
RenderingServer.set_default_clear_color(color)
|
||||||
@@ -206,6 +208,12 @@ func _on_stream_deck_check_toggled(button_pressed):
|
|||||||
get_node("/root/ElgatoStreamDeck").refresh_connection()
|
get_node("/root/ElgatoStreamDeck").refresh_connection()
|
||||||
Global.pushUpdate("StreamDeck integration " + ("enabled" if button_pressed else "disabled") + ".")
|
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):
|
func _process(delta):
|
||||||
var g = to_local(get_global_mouse_position())
|
var g = to_local(get_global_mouse_position())
|
||||||
|
|||||||
Reference in New Issue
Block a user