Unfortunately you can't have "on speech ended" inside a function as it is a triggered condition.
Functions are in some way also a triggered condition, namely when the function is called.
Since the code runs sequentially, one can't have two conditional triggers at the same time.
Per se you can only have one condition trigger (green arrow indication) in a condition block and its sub events.
To utilize "on speech ended" then, your approach has to be changed in a certain way.