There is a way for distinction: intonation
As stated by the OP, the meaning is clear once we know whether the sentence is declarative or a question. The key point about identifying the sentence type in a conversation, other than the context, is intonation.
I asked a friend who is a native speaker of mandarin (from Shanghai) to pronounce the following sentences:
- 那里有几个人? (How many people is there?)
- 那里有几个人. (There are a few people.)
He argued in the interrogative sentence he stressed the question word 几, while in the declarative sentence, he stressed the object 人.
General discussion: declarative vs question intonation
Apart from lexical tones, mandarin chinese like most languages has a sentence intonation. Sentence intonation can be thought of the overlaying tune of the sentence, with fluctuations given by the lexical tones . Surprisingly, the study of sentence intonation and its interaction with the lexical tones is a complex topic, which is still active in linguistics research.
Wh-words, the interrogative words such as shénme 什么, shéi 谁 or jǐ 几 can sometimes be ambiguous between a declarative and question interpretation. This is precisely the topic of study of an article from last month . Considering sentences like the example I gave above for wh-words, they studied the intonation of the interrogative vs declarative sentences, and found the following results:
- Questions are spoken faster than declarations.
- Questions have more 'focus' in the wh-words (as my friend said): with a longer duration, a steep pitch rise and a stronger volume change (what is called intensity range).
- Questions usually maintain the pitch raised at the wh-word until the end of the sentence.
- Declarations have more focus at the verb and wh-words are instead largely suppressed with an almost flat pitch, a short duration and a small volume change.
 Crosswhite, K. M., & McDonough, J. (2000). Comparison of intonation patters in Mandarine and English for a particular Speaker. University of Rochester Working Papers in the Language Science, 1, 24-55.
 Yang, Y., Gryllia, S., & Cheng, L. L. S. (2020). Wh-question or wh-declarative? Prosody makes the difference. Speech Communication, 118, 21-32 (see link).