Skip to content

Commit eb27a35

Browse files
authored
Merge pull request #296 from marcelofg55/mic_record
Added MicRecord demo
2 parents 77f7afa + 4534050 commit eb27a35

File tree

9 files changed

+210
-0
lines changed

9 files changed

+210
-0
lines changed

audio/mic_record/Intro.ogg

684 KB
Binary file not shown.

audio/mic_record/Intro.ogg.import

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[remap]
2+
3+
importer="ogg_vorbis"
4+
type="AudioStreamOGGVorbis"
5+
path="res://.import/Intro.ogg-dfe75727d0e47692e220adf97ddb7ad9.oggstr"
6+
7+
[deps]
8+
9+
source_file="res://Intro.ogg"
10+
dest_files=[ "res://.import/Intro.ogg-dfe75727d0e47692e220adf97ddb7ad9.oggstr" ]
11+
12+
[params]
13+
14+
loop=true
15+
loop_offset=0

audio/mic_record/Node2D.gd

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
extends Node2D
2+
3+
var effect
4+
var recording
5+
6+
func _ready():
7+
var idx = AudioServer.get_bus_index("Record")
8+
effect = AudioServer.get_bus_effect(idx, 0)
9+
10+
func _on_RecordButton_pressed():
11+
if (effect.is_recording_active()):
12+
recording = effect.get_recording()
13+
$PlayButton.disabled = false
14+
$SaveButton.disabled = false
15+
effect.set_recording_active(false)
16+
$RecordButton.text = "Record"
17+
else:
18+
$PlayButton.disabled = true
19+
$SaveButton.disabled = true
20+
effect.set_recording_active(true)
21+
$RecordButton.text = "Stop"
22+
23+
func _on_PlayButton_pressed():
24+
print(recording)
25+
print(recording.format)
26+
print(recording.mix_rate)
27+
print(recording.stereo)
28+
var data = recording.get_data()
29+
print(data)
30+
print(data.size())
31+
$AudioStreamPlayer.stream = recording
32+
$AudioStreamPlayer.play()
33+
34+
func _on_Play_Music_pressed():
35+
if ($AudioStreamPlayer2.playing):
36+
$AudioStreamPlayer2.stop()
37+
$PlayMusic.text = "Play Music"
38+
else:
39+
$AudioStreamPlayer2.play()
40+
$PlayMusic.text = "Stop Music"
41+
42+
func _on_SaveButton_pressed():
43+
recording.save_to_wav($SaveButton/Filename.text)

audio/mic_record/Node2D.tscn

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[gd_scene load_steps=4 format=2]
2+
3+
[ext_resource path="res://Node2D.gd" type="Script" id=1]
4+
[ext_resource path="res://Intro.ogg" type="AudioStream" id=2]
5+
6+
[sub_resource type="AudioStreamMicrophone" id=1]
7+
8+
9+
[node name="Node2D" type="Node2D"]
10+
script = ExtResource( 1 )
11+
12+
[node name="AudioStreamRecord" type="AudioStreamPlayer" parent="."]
13+
stream = SubResource( 1 )
14+
autoplay = true
15+
bus = "Record"
16+
17+
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
18+
autoplay = true
19+
20+
[node name="AudioStreamPlayer2" type="AudioStreamPlayer" parent="."]
21+
stream = ExtResource( 2 )
22+
volume_db = -6.0
23+
24+
[node name="RecordButton" type="Button" parent="."]
25+
margin_left = 120.0
26+
margin_top = 60.0
27+
margin_bottom = 78.0
28+
text = "Record"
29+
30+
[node name="SaveButton" type="Button" parent="."]
31+
editor/display_folded = true
32+
margin_left = 120.0
33+
margin_top = 120.0
34+
disabled = true
35+
text = "Save Wav To:"
36+
37+
[node name="Filename" type="Label" parent="SaveButton"]
38+
margin_left = 120.0
39+
margin_right = 440.0
40+
margin_bottom = 20.0
41+
text = "user://record.wav"
42+
43+
[node name="PlayButton" type="Button" parent="."]
44+
margin_left = 240.0
45+
margin_top = 60.0
46+
disabled = true
47+
text = "Play"
48+
49+
[node name="PlayMusic" type="Button" parent="."]
50+
margin_left = 120.0
51+
margin_top = 180.0
52+
text = "Play Music"
53+
54+
[connection signal="pressed" from="RecordButton" to="." method="_on_RecordButton_pressed"]
55+
[connection signal="pressed" from="SaveButton" to="." method="_on_SaveButton_pressed"]
56+
[connection signal="pressed" from="PlayButton" to="." method="_on_PlayButton_pressed"]
57+
[connection signal="pressed" from="PlayMusic" to="." method="_on_Play_Music_pressed"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[gd_resource type="AudioBusLayout" load_steps=2 format=2]
2+
3+
[sub_resource type="AudioEffectRecord" id=1]
4+
5+
resource_name = "Record"
6+
7+
[resource]
8+
9+
bus/1/name = "Record"
10+
bus/1/solo = false
11+
bus/1/mute = true
12+
bus/1/bypass_fx = false
13+
bus/1/volume_db = 0.0
14+
bus/1/send = "Master"
15+
bus/1/effect/0/effect = SubResource( 1 )
16+
bus/1/effect/0/enabled = true
17+

audio/mic_record/default_env.tres

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[gd_resource type="Environment" load_steps=2 format=2]
2+
3+
[sub_resource type="ProceduralSky" id=1]
4+
5+
sky_top_color = Color( 0.647059, 0.839216, 0.945098, 1 )
6+
sky_horizon_color = Color( 0.839216, 0.917647, 0.980392, 1 )
7+
ground_bottom_color = Color( 0.156863, 0.184314, 0.211765, 1 )
8+
ground_horizon_color = Color( 0.423529, 0.396078, 0.372549, 1 )
9+
10+
[resource]
11+
12+
background_mode = 2
13+
background_sky = SubResource( 1 )
14+

audio/mic_record/icon.png

3.35 KB
Loading

audio/mic_record/icon.png.import

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="StreamTexture"
5+
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
6+
7+
[deps]
8+
9+
source_file="res://icon.png"
10+
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
11+
12+
[params]
13+
14+
compress/mode=0
15+
compress/lossy_quality=0.7
16+
compress/hdr_mode=0
17+
compress/bptc_ldr=0
18+
compress/normal_map=0
19+
flags/repeat=0
20+
flags/filter=true
21+
flags/mipmaps=false
22+
flags/anisotropic=false
23+
flags/srgb=2
24+
process/fix_alpha_border=true
25+
process/premult_alpha=false
26+
process/HDR_as_SRGB=false
27+
process/invert_color=false
28+
stream=false
29+
size_limit=0
30+
detect_3d=true
31+
svg/scale=1.0

audio/mic_record/project.godot

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; Engine configuration file.
2+
; It's best edited using the editor UI and not directly,
3+
; since the parameters that go here are not all obvious.
4+
;
5+
; Format:
6+
; [section] ; section goes between []
7+
; param=value ; assign values to parameters
8+
9+
config_version=4
10+
11+
_global_script_classes=[ ]
12+
_global_script_class_icons={
13+
14+
}
15+
16+
[application]
17+
18+
config/name="MicRecord"
19+
run/main_scene="res://Node2D.tscn"
20+
config/icon="res://icon.png"
21+
22+
[audio]
23+
24+
enable_audio_input=true
25+
26+
[display]
27+
28+
window/size/width=640
29+
window/size/height=480
30+
31+
[rendering]
32+
33+
environment/default_environment="res://default_env.tres"

0 commit comments

Comments
 (0)