There are a couple of different USB devices (usually sold as just cables) that communicate with an app on the Android device. I tried a few that worked well at first, but for some reason became flakier and flakier until they wouldn't even start after a year or so. I'm pretty sure that the devices are still fine, but the app updates killed the functionality by degrees, to lock out clones and force customers to buy a new device periodically.
However, there is one decent company with a reliable software and device chain: DisplayLink. They have a free app, and sell their chips to various equipment manufacturers, as well as making some of their own.
I will warn you that you need to be careful about buying equipment that carries the DisplayLink compatibility logo, because there are some devices that use their chips but don't support the software. You also need to make sure that the device will work with your phone, i.e. USB 2.0 or USB 3.x. Not all USB-C ports are automatically USB 3.x.
I got a secondhand HP device intended to be used with laptops for a second display output, but it works great with my phone. HDMI output with sound and negligible lag. I can even use it with a hub and have a wired controller at the same time. Now if only my phone supported simultaneous charge and OTG hosting. Ah well.
I don't know if this will work or even compile, but I feel like I'm pretty close.