|
@@ -38,6 +38,20 @@ An ``AudioStreamPlayer`` named ``AudioStreamRecord`` is used for recording.
|
|
# as an "AudioEffectRecord" resource.
|
|
# as an "AudioEffectRecord" resource.
|
|
effect = AudioServer.get_bus_effect(idx, 0)
|
|
effect = AudioServer.get_bus_effect(idx, 0)
|
|
|
|
|
|
|
|
+ .. code-tab:: csharp
|
|
|
|
+
|
|
|
|
+ private AudioEffectRecord _effect;
|
|
|
|
+ private AudioStreamSample _recording;
|
|
|
|
+
|
|
|
|
+ public override void _Ready()
|
|
|
|
+ {
|
|
|
|
+ // We get the index of the "Record" bus.
|
|
|
|
+ int idx = AudioServer.GetBusIndex("Record");
|
|
|
|
+ // And use it to retrieve its first effect, which has been defined
|
|
|
|
+ // as an "AudioEffectRecord" resource.
|
|
|
|
+ _effect = (AudioEffectRecord)AudioServer.GetBusEffect(idx, 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
The audio recording is handled by the :ref:`class_AudioEffectRecord` resource
|
|
The audio recording is handled by the :ref:`class_AudioEffectRecord` resource
|
|
which has three methods:
|
|
which has three methods:
|
|
:ref:`get_recording() <class_AudioEffectRecord_method_get_recording>`,
|
|
:ref:`get_recording() <class_AudioEffectRecord_method_get_recording>`,
|
|
@@ -62,6 +76,29 @@ and :ref:`set_recording_active() <class_AudioEffectRecord_method_set_recording_a
|
|
$RecordButton.text = "Stop"
|
|
$RecordButton.text = "Stop"
|
|
$Status.text = "Recording..."
|
|
$Status.text = "Recording..."
|
|
|
|
|
|
|
|
+ .. code-tab:: csharp
|
|
|
|
+
|
|
|
|
+ public void OnRecordButtonPressed()
|
|
|
|
+ {
|
|
|
|
+ if (_effect.IsRecordingActive())
|
|
|
|
+ {
|
|
|
|
+ _recording = _effect.GetRecording();
|
|
|
|
+ GetNode<Button>("PlayButton").Disabled = false;
|
|
|
|
+ GetNode<Button>("SaveButton").Disabled = false;
|
|
|
|
+ _effect.SetRecordingActive(false);
|
|
|
|
+ GetNode<Button>("RecordButton").Text = "Record";
|
|
|
|
+ GetNode<Label>("Status").Text = "";
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ GetNode<Button>("PlayButton").Disabled = true;
|
|
|
|
+ GetNode<Button>("SaveButton").Disabled = true;
|
|
|
|
+ _effect.SetRecordingActive(true);
|
|
|
|
+ GetNode<Button>("RecordButton").Text = "Stop";
|
|
|
|
+ GetNode<Label>("Status").Text = "Recording...";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
At the start of the demo, the recording effect is not active. When the user
|
|
At the start of the demo, the recording effect is not active. When the user
|
|
presses the ``RecordButton``, the effect is enabled with
|
|
presses the ``RecordButton``, the effect is enabled with
|
|
``set_recording_active(true)``.
|
|
``set_recording_active(true)``.
|
|
@@ -84,6 +121,22 @@ the recorded stream can be stored into the ``recording`` variable by calling
|
|
$AudioStreamPlayer.stream = recording
|
|
$AudioStreamPlayer.stream = recording
|
|
$AudioStreamPlayer.play()
|
|
$AudioStreamPlayer.play()
|
|
|
|
|
|
|
|
+ .. code-tab:: csharp
|
|
|
|
+
|
|
|
|
+ public void OnPlayButtonPressed()
|
|
|
|
+ {
|
|
|
|
+ GD.Print(_recording);
|
|
|
|
+ GD.Print(_recording.Format);
|
|
|
|
+ GD.Print(_recording.MixRate);
|
|
|
|
+ GD.Print(_recording.Stereo);
|
|
|
|
+ byte[] data = _recording.Data;
|
|
|
|
+ GD.Print(data);
|
|
|
|
+ GD.Print(data.Length);
|
|
|
|
+ var audioStreamPlayer = GetNode<AudioStreamPlayer>("AudioStreamPlayer");
|
|
|
|
+ audioStreamPlayer.Stream = _recording;
|
|
|
|
+ audioStreamPlayer.Play();
|
|
|
|
+ }
|
|
|
|
+
|
|
To playback the recording, you assign the recording as the stream of the
|
|
To playback the recording, you assign the recording as the stream of the
|
|
``AudioStreamPlayer`` and call ``play()``.
|
|
``AudioStreamPlayer`` and call ``play()``.
|
|
|
|
|
|
@@ -95,5 +148,14 @@ To playback the recording, you assign the recording as the stream of the
|
|
recording.save_to_wav(save_path)
|
|
recording.save_to_wav(save_path)
|
|
$Status.text = "Saved WAV file to: %s\n(%s)" % [save_path, ProjectSettings.globalize_path(save_path)]
|
|
$Status.text = "Saved WAV file to: %s\n(%s)" % [save_path, ProjectSettings.globalize_path(save_path)]
|
|
|
|
|
|
|
|
+ .. code-tab:: csharp
|
|
|
|
+
|
|
|
|
+ public void OnSavebuttonPressed()
|
|
|
|
+ {
|
|
|
|
+ string savePath = GetNode<LineEdit>("SaveButton/Filename").Text;
|
|
|
|
+ _recording.SaveToWav(savePath);
|
|
|
|
+ GetNode<Label>("Status").Text = string.Format("Saved WAV file to: {0}\n({1})", savePath, ProjectSettings.GlobalizePath(savePath));
|
|
|
|
+ }
|
|
|
|
+
|
|
To save the recording, you call ``save_to_wav()`` with the path to a file.
|
|
To save the recording, you call ``save_to_wav()`` with the path to a file.
|
|
In this demo, the path is defined by the user via a ``LineEdit`` input box.
|
|
In this demo, the path is defined by the user via a ``LineEdit`` input box.
|