Added MicRecord demo

This commit is contained in:
Marcelo Fernandez
2018-12-15 14:45:28 -03:00
parent 77f7afaba4
commit 453405031c
9 changed files with 210 additions and 0 deletions

BIN
audio/mic_record/Intro.ogg Normal file

Binary file not shown.

View File

@@ -0,0 +1,15 @@
[remap]
importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/Intro.ogg-dfe75727d0e47692e220adf97ddb7ad9.oggstr"
[deps]
source_file="res://Intro.ogg"
dest_files=[ "res://.import/Intro.ogg-dfe75727d0e47692e220adf97ddb7ad9.oggstr" ]
[params]
loop=true
loop_offset=0

View File

@@ -0,0 +1,43 @@
extends Node2D
var effect
var recording
func _ready():
var idx = AudioServer.get_bus_index("Record")
effect = AudioServer.get_bus_effect(idx, 0)
func _on_RecordButton_pressed():
if (effect.is_recording_active()):
recording = effect.get_recording()
$PlayButton.disabled = false
$SaveButton.disabled = false
effect.set_recording_active(false)
$RecordButton.text = "Record"
else:
$PlayButton.disabled = true
$SaveButton.disabled = true
effect.set_recording_active(true)
$RecordButton.text = "Stop"
func _on_PlayButton_pressed():
print(recording)
print(recording.format)
print(recording.mix_rate)
print(recording.stereo)
var data = recording.get_data()
print(data)
print(data.size())
$AudioStreamPlayer.stream = recording
$AudioStreamPlayer.play()
func _on_Play_Music_pressed():
if ($AudioStreamPlayer2.playing):
$AudioStreamPlayer2.stop()
$PlayMusic.text = "Play Music"
else:
$AudioStreamPlayer2.play()
$PlayMusic.text = "Stop Music"
func _on_SaveButton_pressed():
recording.save_to_wav($SaveButton/Filename.text)

View File

@@ -0,0 +1,57 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://Node2D.gd" type="Script" id=1]
[ext_resource path="res://Intro.ogg" type="AudioStream" id=2]
[sub_resource type="AudioStreamMicrophone" id=1]
[node name="Node2D" type="Node2D"]
script = ExtResource( 1 )
[node name="AudioStreamRecord" type="AudioStreamPlayer" parent="."]
stream = SubResource( 1 )
autoplay = true
bus = "Record"
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
autoplay = true
[node name="AudioStreamPlayer2" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 2 )
volume_db = -6.0
[node name="RecordButton" type="Button" parent="."]
margin_left = 120.0
margin_top = 60.0
margin_bottom = 78.0
text = "Record"
[node name="SaveButton" type="Button" parent="."]
editor/display_folded = true
margin_left = 120.0
margin_top = 120.0
disabled = true
text = "Save Wav To:"
[node name="Filename" type="Label" parent="SaveButton"]
margin_left = 120.0
margin_right = 440.0
margin_bottom = 20.0
text = "user://record.wav"
[node name="PlayButton" type="Button" parent="."]
margin_left = 240.0
margin_top = 60.0
disabled = true
text = "Play"
[node name="PlayMusic" type="Button" parent="."]
margin_left = 120.0
margin_top = 180.0
text = "Play Music"
[connection signal="pressed" from="RecordButton" to="." method="_on_RecordButton_pressed"]
[connection signal="pressed" from="SaveButton" to="." method="_on_SaveButton_pressed"]
[connection signal="pressed" from="PlayButton" to="." method="_on_PlayButton_pressed"]
[connection signal="pressed" from="PlayMusic" to="." method="_on_Play_Music_pressed"]

View File

@@ -0,0 +1,17 @@
[gd_resource type="AudioBusLayout" load_steps=2 format=2]
[sub_resource type="AudioEffectRecord" id=1]
resource_name = "Record"
[resource]
bus/1/name = "Record"
bus/1/solo = false
bus/1/mute = true
bus/1/bypass_fx = false
bus/1/volume_db = 0.0
bus/1/send = "Master"
bus/1/effect/0/effect = SubResource( 1 )
bus/1/effect/0/enabled = true

View File

@@ -0,0 +1,14 @@
[gd_resource type="Environment" load_steps=2 format=2]
[sub_resource type="ProceduralSky" id=1]
sky_top_color = Color( 0.647059, 0.839216, 0.945098, 1 )
sky_horizon_color = Color( 0.839216, 0.917647, 0.980392, 1 )
ground_bottom_color = Color( 0.156863, 0.184314, 0.211765, 1 )
ground_horizon_color = Color( 0.423529, 0.396078, 0.372549, 1 )
[resource]
background_mode = 2
background_sky = SubResource( 1 )

BIN
audio/mic_record/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@@ -0,0 +1,31 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
[deps]
source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@@ -0,0 +1,33 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=4
_global_script_classes=[ ]
_global_script_class_icons={
}
[application]
config/name="MicRecord"
run/main_scene="res://Node2D.tscn"
config/icon="res://icon.png"
[audio]
enable_audio_input=true
[display]
window/size/width=640
window/size/height=480
[rendering]
environment/default_environment="res://default_env.tres"