If your device has a headphone jack or you are okay using its built-in speaker, you can simply use an Apple USB to Lightning adapter (for iOS devices with Lightning ports) or a micro-USB to USB-C adapter (for all devices with a USB-C port). For older Android devices with a micro-USB port, you'll need to use a USB "On-The-Go" (OTG) adapter.
It has gotten a bit more difficult to use USB-MIDI controllers with headphones because many new devices don't come with 3.5 mm headphone jacks. However, the correct adapter can add a headphone jack to your phone or tablet. For iOS devices (iPhone or iPad) with a Lightning port, I suggest
this adapter or a similar one (look for mentions in the dscription or reviews that it works with MIDI keyboards). You can also use a USB hub plugged into an Apple USB to Lightning adapter. For devices with micro USB or USB-C connectors (all Android devices and newer iPads), a USB hub is a great option.
This is an example of a compact USB-C hub, though it may interfere with a case on your phone or tablet. There are also many hubs available with short cables that will be less likely to inferere with a case.
Here's one example. If your device has an older micro-USB port, you'd want to search for a micro-USB hub instead. In the coming years it's likely that all new portable devices will have USB-C ports, which will making selecting an adapter/hub a bit simpler. Feel free to contact me for suggestions for selecting an adapter or hub.