Soliton regime of generation of terahertz radiation taking into account the phase of an optical pulse