I had copied exactly as you had written and was using the background talking in the room function :
function repeatedly_execute() {
  if (qIsTalking()==0) { Â
    qDisplaySpeech(EGO, "blah blah");
    qDisplaySpeech(EGO, Delay(20));
    qDisplaySpeech(EGO, "more blah");
    qDisplaySpeech(EGO, Delay(70)); Â
  }
}
And when the player left the room the background talking was continuing in the next room, and it was here that I was placing the "qStopSpeech()" to counteract it.
Ok, first let's sort out the qStopSpeech() problem because it's related to the other question. If I understand you correctly the above code is placed in the *room* repeatedly execute interaction event, right? I ask because you typed "function repeatedly_execute()" what usually is the name of global repeatedly execute which should be placed in the main global script file.
Also, I assume EGO is an NPC and not a player character.
The fact qStopSpeech() does its job when you put it within room's repeatedly execute means the function itself works properly. I guess there is a problem with on_event part, let's see...
Could you modify you main global script
on_event function like this:
function on_event(int event, int data) {
// ...
// ...
// some other code may be here
// ...
// ...
// move the following lines at the very
// end of on_event function:
//
if (event == LEAVE_ROOM) {
Display("qIsTalking1 = %d", qIsTalking());
qStopSpeech();
Display("qIsTalking2 = %d", qIsTalking());
}}
Now, the background talking is started in the first room that causes the trouble (ie. backgroung talking does not stop when you leave it) and just before the player leaves the room you should see two displays:
qIsTalking1 = SOME NUMBER
qIsTalking2 = SOME NUMBER
So tell me please what there numbers are, for qIsTalking1 and qIsTalking2 respectively.
And let me know if it doesn't display anything at all.
how did you workout the sizes for
#define BUFFER_SIZE 300
#define AGS_STRING_LENGTH 200
and what effect would there be increasing these values?
AGS_STRING_LENGTH is the maximum length of an AGS string, you should not change it because it can cause serious problems with some versions of AGS, apart from that it won't change anything (for instance, if you increased the value it would just take more system memory and nothing else).
BUFFER_SIZE specifies the size of the buffer to store queued speech messages, it determines how many qDisplaySpeech calls you can have in one go, ie:
if (qIsTalking()==0) {Â Â
 qDisplaySpeech();
 qDisplaySpeech();
 qDisplaySpeech();
 qDisplaySpeech(); Â
 ....
 ....
 etc but not more than BUFFER_SIZE in total
}
You can increase it which would take up more memory but I believe 300 is more than enough.

p.s. So post those qIsTalking1, qIsTalking2 numbers so that we could resolve the original problem and I could then post a working example for the "changing characters" question.