Disclaimer: I don't know what I'm talking about
Asterisk could be a good place to start. It's an open source VoIP server where you can host your own number(s). IIRC owning and running a number requires a small subscription which will vary depending on the provider you choose.