When a sound wave travels from one medium to another, it undergoes a phenomenon called refraction. Refraction occurs because the speed of sound changes as it passes from one medium to another with a different acoustic impedance. The acoustic impedance depends on the density and sound speed of the medium.
In the scenario you described, where two media with different sound speeds are connected along each other, it is possible for a sound wave to produce a shock wave under certain conditions. A shock wave is a sudden change in pressure and velocity, and it typically occurs when the wavefront of a sound wave becomes steep enough that it forms a discontinuity. This can happen when the sound wave is traveling at a supersonic speed relative to the medium it is passing through.
If the medium with the slower sound speed is encountered first by the sound wave, and the sound wave's speed is supersonic relative to that medium, a shock wave can be generated at the interface between the two media. The shock wave would form as the sound wave enters the medium with the faster sound speed. The abrupt change in sound speed at the interface can lead to a shock wave formation.
It's worth noting that the exact conditions for shock wave formation depend on various factors, including the specific sound speeds and densities of the media involved, the angle of incidence of the sound wave, and the energy and frequency of the sound wave. Additionally, shock waves are typically associated with high-energy disturbances, such as those produced by explosions or high-speed objects, rather than ordinary sound waves.