You must be knowing that there are kinds of japa or chanting viz- vAchika, upAnsu and mAnasika.
The Visuddheswara Tantram defines them as follows:
NijakarnAgocharohayam Sajapo MAnasah Smrito | UpAnsunijakarnasya
Gocharaha Parikirtitaha | MantromucchArayedvAchA Sajapo VAchika Smrito
When the chants are completely done in one's mind and they are not
audible even to oneself its called mAnasa. When its done like whispers
and the chants are audible to one's own ears then its called upAnsu.
Loud japa which everyone around can hear is called vAchika japa.
Among these 3 kinds of japa, the scriptures say that the mAnasika japa is the best followed by upAnsu followed by vAchika.
The ShivAgama states:
TasmAcchatagunopansuhu Sahasro MAnasah Smritoho |
UpAnsu japa is 100 times more fruitful than vAchika and mAnasa 1000
Now, if you are doing japa loudly (vAchika) then there are many rules to be followed. Your purity matters, the purity of the place of japa matters etc. But in case of mental chanting (mAnasa) there are absolutely no such restrictions.
See the following verses from VaRahi Tantram:
Ushnishi Kanchuki Nagno Muktakeso Ganabritoho | Apavitrakarohoshuddhah
Pralapanna Japeth Kacchit || AnAsanaha SayAno VA Gacchana BhunjAn Eva
VA | ApPrAvritokarou KritvA SirovA PrAvritopi VA..... PrsArya Na
Japeth PAdAvuthkatAsna Eva VA ||...
Japa becomes fruitless if done with head gear, chest gears on, while
naked, while hair not tied, while surrounded by friends, with impure hands,
while traveling or walking, while lying down on bed, while eating,
while one is hungry, while one's mind is disturbed, while one is angry
or sad..., while on roads, in impure places, with shoes on, while sitting on
the utkata asana etc..
Now, the above rules apply for loud japa. For mAnasa japa there are no rules as stated in the following verses:
MAnase Tu Niyamo NAstyeva | TathAcha Asuchirbba SuchirvApi Gacchan Stishthan Swapannapi | ... Na Dosha MAnase JApye Sarvadesepi
There are no rules for mAnasa japa. Whether one is pure or impure ,
whether one is traveling, eating or while lying on bed mental japa
can always be done.... There are no sthanAdi doshas in mAnasa japa.
(That is there is no need to consider purity of place of japa etc).