In this paper we analyse the process of the generation of Tollmien–Schlichting waves in a laminar boundary layer on an aircraft wing in the transonic flow regime. We assume that the boundary layer is exposed to a weak acoustic noise. As it penetrates the boundary layer, the Stokes layer forms on the wing surface. We further assume that the boundary layer encounters a local roughness on the wing surface in the form of a gap, step or hump. The interaction of the unsteady perturbations in the Stokes layer with steady perturbations produced by the wall roughness is shown to lead to the formation of the Tollmien–Schlichting wave behind the roughness. The ability of the flow in the boundary layer to convert ‘external perturbations’ into instability modes is termed the receptivity of the boundary layer. In this paper we first develop the linear receptivity theory. Assuming the Reynolds number to be large, we use the transonic version of the viscous–inviscid interaction theory that is known to describe the stability of the boundary layer on the lower branch of the neutral curve. The linear receptivity theory holds when the acoustic noise level is weak, and the roughness height is small. In this case we were able to deduce an analytic formula for the amplitude of the generated Tollmien–Schlichting wave. In the second part of the paper we lift the restriction on the roughness height, which allows us to study the flows with local separation regions. A new ‘direct’ numerical method has been developed for this purpose. We performed the calculations for different values of the Kármán–Guderley parameter, and found that the flow separation leads to a significant enhancement of the receptivity process.