import io
import wave


def raw_bytes_to_wav(data: bytes, frame_rate: int, channels: int, sample_width: int) -> bytes:
    """
    Convert raw PCM bytes to wav bytes (with the initial 44 bytes header)
    """

    out = io.BytesIO()
    wf = wave.open(out, "wb")
    wf.setnchannels(channels)
    wf.setsampwidth(sample_width)
    wf.setframerate(frame_rate)
    wf.writeframes(data)
    wf.close()
    return out.getvalue()