Must Electrical Adapters Be Inside Gang Boxes?
In general, AC 120 and 240 wiring may not be terminated in a wall except in approved boxes or fixtures. And those boxes must be accessible. You cannot splice wires in a wall without boxes (except for certain approved in-line splices), and you cannot bury a box in a wall without an accessible cover.

That means you need to attach the DC adapter (basically a transformer) to an approved electrical box. This is usually done with the transformer bolted to the outside of the box with the wires from AC side of the box feeding inside, where they are attached to the line in. And this box must remain accessible, with a cover that can be removed to get to the wiring.

If this is not aesthetically pleasing, you may be able to locate the DC adapter somewhere else (in a basement or an attic) with an appropriate box, and then run low voltage wires to your speaker.

If this is a plug in adapter, you need to attach it to a conventional outlet in a conventional box, not buried in a wall.