Praise be to Allah.
It was narrated from Abu Hurayrah (may Allah be pleased with him) that the Messenger of Allah (blessings and peace of Allah be upon him) said: “Fasting is a shield, so let [the fasting person] not utter any obscene or ignorant speech, and if someone tries to fight him or insults him, let him say: ‘I am fasting,’ twice.” Narrated by al-Bukhaari (1894) and Muslim (1151).
Ibn ‘Abd al-Barr (may Allah have mercy on him) said:
With regard to the words “and if someone tries to fight him or insults him, let him say: ‘I am fasting’”, there are two views:
The first view is that he should say to the one who wants to insult him or fight him: I am fasting, and my fast prevents me from responding to you in kind, because I am guarding my fast against obscene talk or false speech. This is what I am commanded to do, and if it were not for that, I would have stood up for myself and said to you exactly what you said to me, and so on.
The second view is that the fasting person should say to himself: You are fasting, so you have no way to vent your anger by returning insults. And he should not say “I am fasting” out loud, because that is a kind of showing off and telling people about his deeds, because fasting is an action that is not obvious, and that is why Allah will reward without measure the one who fasts.
End quote from at-Tamheed (19/55-56).
What is most likely to be the case is that it should be said out loud, because uttering out loud is what is meant by the word “say”.
An-Nawawi (may Allah have mercy on him) said: It was said that he should say it out loud to make the one who insulted him hear it, in the hope that he will be deterred. And it was said that he should say it to himself, in order to refrain from saying foolish things and maintain the integrity of his fast. The first view is more likely to be correct.
End quote from al-Adhkaar (p. 161).
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) said:
The correct view is that he should say it out loud, as is indicated by the hadith, because when saying is mentioned in general terms, without qualification, it can only refer to what is uttered out loud, whereas what a person says to himself is usually mentioned with qualification, as in the hadith, “Allah has pardoned my ummah for what crosses their minds [lit. what they say to themselves],” which is then followed by the words: “so long as they do not speak of it or act upon it.” When speaking is mentioned in general terms, it can only refer to what is audible, and if a person says out loud, I am fasting, then he has explained the reason why he is refraining from responding, and that will be a better deterrent to the one who initiated the aggression.
End quote from Minhaaj as-Sunnah (5/197).
Based on the wording of the hadith and the reason why the Prophet (blessings and peace of Allah be upon him) said this, which was to address the opponent and tell him to restrain himself, it is more appropriate that the words “I am fasting” should be said out loud.
But adding the word Allahumma (O Allah) does not change the meaning; rather it makes the meaning more emphatic, by calling upon Allah to witness that. This is like the response of the Prophet (blessings and peace of Allah be upon him) to the man who asked him about the teachings of Islam:
… The man said to the Prophet (blessings and peace of Allah be upon him): I am going to ask you something and I will be stern in asking, so do not be upset with me.
The Prophet (blessings and peace of Allah be upon him) said: Ask whatever you want.
He said: I ask you, by your Lord and the Lord of those who came before you, has Allah sent you to all of humankind?
He said: Allahumma na‘m (O Allah, yes)…
Narrated by al-Bukhaari (63).
Al-Haafiz Ibn Hajar (may Allah have mercy on him) said:
With regard to his saying “Allahumma na‘m (O Allah, yes)” when simply saying yes would have been a sufficient answer, he only said “Allahumma (O Allah)” by way of seeking blessing, and it is as if he was calling on Allah to witness that by way of affirming his truthfulness.
End quote from Fath al-Baari (1/151).
And Allah knows best.