godot-psd-training/Communication/voice_communication.gd

53 lines
1.4 KiB
GDScript

extends Node
var effect: AudioEffectRecord
var recording: AudioStreamWAV
var record_stream: AudioStreamWAV
func _ready():
# We get the index of the "Record" bus.
var idx = AudioServer.get_bus_index("Record")
# And use it to retrieve its first effect, which has been defined
# as an "AudioEffectRecord" resource.
effect = AudioServer.get_bus_effect(idx, 0)
record_stream = AudioStreamWAV.new()
startRecord()
## 启动录音
func startRecord():
if not effect.is_recording_active():
effect.set_recording_active(true)
## 停止录音
func stopRecord():
if effect.is_recording_active():
effect.set_recording_active(false)
var audio_sd = preload("res://Communication/Assets/shoudao.mp3")
var audio_zlgzmhfzc = preload("res://Communication/Assets/zhenglieguzhangmenhuifuzhengchang.mp3")
func _on_timer_timeout():
if effect.is_recording_active():
var vdb = $AudioStreamRecord.get_volume_db()
print(vdb)
#if effect.is_recording_active():
#recording = effect.get_recording()
#print(recording.data.size(), ", ", recording.format, ", ", recording.loop_mode, ", ", recording.get_length())
#stopRecord()
#var player = AudioStreamPlayer.new()
#add_child(player)
#player.stream = recording
#player.play()
#player.finished.connect( _on_audio_play_finished.bind(player))
#startRecord()
func _on_audio_play_finished(player):
print(player, "播放完成")
player.stop()
player.queue_free()
pass