I am currently trying to add a question mark to sentences that start with "what" at the beginning of the sentences, but can't think of away to do it. For everything that is in the sentences, I can simply use:
if (result.includes(" if")) { result = result.replace(" if", ", if "); }
Maybe one of you can think of another way to use, maybe even the same code, to achieve that objective.
The second problem is in regard to punctuation. I was thinking about setting a period every time the speaker pauses for a few seconds, but would not know how to program this.
*I know there are some libraries and API's, but I chose this way.
CodePudding user response:
let speechStr = "what if I don't."
let strsplit = speechStr.split(" ")
for(let i = 0; i < strsplit.length; i ){
if(strsplit[i].toLowerCase() === 'what'){
speechStr = speechStr.slice(0,-1) '?'
}
}
console.log(speechStr)
try use the example you talked about to avoid confusion