Out of Court settlement in a criminal matter

I am charged with sexual harassment of a barmaid but I committed the offence at a bar when I was already drunk. Hearing of the case has started but prosecution case is yet to be closed. I have spoken to the complainant and we have agreed to settle the dispute by paying her some money. Does the law allow amicable settlement of a criminal matter without undergoing through plea bargaining process? Will we need to sign a deed of settlement and file it in Court for the Court to close the case? Can the victim later re-open the case that has been closed after amicable settlement? 
JJ, Dar es Salaam

Section 163 of the Criminal Procedure Act [Cap.20 R.E 2019] requires criminal Courts to encourage and facilitate amicable settlement of offences of personal or private nature if, in the opinion of the Court, the public interest does not demand infliction of a penalty for commission of the offence. Sexual harassment is an offence of personal or private nature that can be resolved amicably unless its commission is attributed to special circumstances that warrant the imposition of penalty to the offender.

Amicable settlement under section 163 of the Criminal Procedure Act is different from plea bargaining. Amicable settlement involves the accused and the victim; no prosecutor and investigator are involved in the process as it is the case with plea bargaining. The Court can only act as a mediator and take part in approving the terms and conditions of the settlement agreed upon by the victim and the accused. The law neither requires nor bars the signing and filing of a written deed of settlement.

However, we recommend a settlement deed to filed with the trial Court for the Court to approve it and mark the case closed. If the accused fulfils the terms and conditions of the settlement deed and the file is marked closed, the victim cannot later on reopen the same matter. Hence, in paying the victim, the accused should make sure the payment is documented and the Court orders closing of the proceedings and the case.