IAX Issue with phones on same local network

I have a client with two companies with several offices across different towns where I live. I have two hosted freepbx servers (one for each company) with an IAX connecting them together. It works fine except for one office that has both companies housed in the same building. In this site when company A calls company B the voice is garbled and has the robot sound. If Company A calls Company B in a seperate office the calls sound fine. They have 400x15 internet so I don’t think it’s a bandwidth issue. I think it may be port related but am not sure. I know that putting these users on the same server would fix but for billing and organization they don’t want to do that. Anyone have any ideas on how to fix?

Interesting problem.

First, confirm that this is related to the intracompany trunk, i.e. in the affected building, calls between two company A extensions are fine, as are calls between two company B extensions.

I assume that the two servers are on separate public IPv4 addresses. If not, provide details.
I assume that in the affected building, the companies each have their own cable modem and router/firewall. If there is a VPN or other connectivity between the networks, confirm that it is not involved in the VoIP path. Also confirm that the extensions are pjsip, Direct Media is set to No and the affected devices are IP phones and/or softphones with wired connectivity to the respective router/firewalls.

When a company A user calls company B, who hears bad sound, A, B or both?
When a company B user calls company A, who hears bad sound, A, B or both?

Thanks for the reply and info. I had them check and didn’t realize that calls to any extension (even from same company) are garbled. Calls to other locations are fine. They share network and internet (they are sister companies). Direct Media is set to no. They are actually getting a new router next week and I’m going to test after I install it.