Inclusion Criteria:  Mechanical ventilation (MV) through an orotracheal tube for at least 48 hours PaO2 /FiO2 ratio ≤ 300 mmHg (during the MV period)  Potential for weaning  Precipitating cause leading to MV in resolution PaO2 /FiO2 ratio ≥ 150 mmHg PEEP ≤ 8 cmH2O pH > 7,25 SpO2 ≥ 90% with FiO2 ≤ 0.4; BPM ≤35 Hemodynamic stability (noradrenaline ≤ 0.1mcg / kg / min and SBP 90-160; HR <140) Temperature <38 ° C Presence of inspiratory effort and appropriate spontaneous cough Decision to perform a spontaneous breathing trial by the attending physician High risk of weaning failure defined by a history of: (i) Previous failed extubation, (ii) Chronic heart or respiratory failure, or (iii) MV ≥ 7 days.  Exclusion Criteria:  Contraindications to NIV or HFNC, which include abnormalities, trauma or surgery of the face or nose. Contraindications for esophageal balloon catheter insertion (eg. severe coagulopathy, esophageal varices, and history of esophageal or gastric surgery) Contraindication for use of electric impedance tomography (eg. Pacemaker) Tracheostomy Refusal to participate by the attending physician Do not resuscitate order