A GDExtension that adds to Godot4 support for encoding voice data using the Opus Codec
Go to file
weil cd69c2b1ca GodotOpus is no longer a singleton; multiple performance improvements 2024-01-17 08:29:33 +01:00
3rdparty/opus Add libopus windows build (x64) 2024-01-16 16:19:26 +01:00
export/addons/opus Add gdextension 2024-01-16 17:34:15 +01:00
godot-cpp@78ffea5b13 Add godot-cpp submodule 2024-01-16 16:13:24 +01:00
src GodotOpus is no longer a singleton; multiple performance improvements 2024-01-17 08:29:33 +01:00
.gitattributes Add libopus windows build (x64) 2024-01-16 16:19:26 +01:00
.gitignore Add encode/decode opus bindings 2024-01-16 16:58:59 +01:00
.gitmodules Add godot-cpp submodule 2024-01-16 16:13:24 +01:00
LICENSE Initial commit 2024-01-16 16:04:07 +01:00
README.md Add build info to the readme 2024-01-16 17:35:33 +01:00
SConstruct Add encode/decode opus bindings 2024-01-16 16:58:59 +01:00

README.md

godot4-opus

A GDExtension that adds to Godot4 support for encoding voice data using the Opus Codec. This can be useful for those who want to implement VOIP systems for Godot4 games.

Overview

This extension adds a new singleton to Godot: Opus with two methods: encode and decode.

These can be used to compress audio obtained AudioEffectCapture and then to decode it so it's usable in Godot again.

Quick and dirty example (full demo coming soon):


func _process_audio() -> void:
    if has_data() and active:
        call_deferred("rpc", "play_data", get_data())

...

func get_data() -> PackedFloat32Array:
    var data = effect.get_buffer(BUFFER_SIZE)
    return Opus.encode(data)

...

@rpc("any_peer", "call_remote", "unreliable_ordered")
func play_data(data: PackedFloat32Array) -> void:
    var id = client.multiplayer.get_remote_sender_id()
    var decoded = Opus.decode(data)
    for b in range(0, BUFFER_SIZE):
        _get_generator(id).push_frame(decoded[b])

Building

In order to build this project, you need scons. Currently only Windows x64 (MSVC) is supported.

  1. Clone repo with submodules (godot-cpp)
git clone --recurse-submodules https://github.com/microtaur/godot4-opus.git && cd godot4-opus
  1. Build debug
scons
  1. Build release
scons target=template_release

More information on building GDExtensions: https://docs.godotengine.org/pl/4.x/tutorials/scripting/gdextension/gdextension_cpp_example.html

Known limitations

  • This is more POC than a production-ready solution although it's not too far from achieving this status. I'm using this code successfully in a scenario similar to the one presented in this demo: https://github.com/godotengine/godot-demo-projects/tree/master/networking/webrtc_signaling
  • Buffer size must be == 480
  • Quality settings are currently hardcoded. Bitrate is 24000; bandwith is OPUS_BANDWIDTH_SUPERWIDEBAND.
  • At the moment this works only on Windows x64. I haven't tried other platforms. Pre-built version of libopus resides in 3rdparty directory.

License

This is MIT licensed. Project uses Opus Codec which is BSD-licensed.