-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add random intervals to make a more natural speech (#8). #9
Conversation
I add a function to generate random timeouts for the execution of the speak function. This adds a more natural speech as was intended by the issue #8.
I added one more treatment to the function. Now, extra white spaces added between the words are removed. This was maded to avoid long random intervals when the white space is found by the function.
Now, all the random intervals are inversely proportional to the interval chosen. Which means: + if the interval chosen is low, the random interval is high. + if the interval chosen is high, the random interval is low. This makes the voices more natural.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Thank you for the PR! After checking the preview deployment, it seems like the randomness is causing a lot of overlapping sounds. Instead of randomized intervals, we can just have an interval for whitespaces. |
Thank you for the review. I will take a look on that. |
I did some tests in Firefox and Chromium. The code did work fine in Firefox, but the audio seems to have some troubles when loading in Chromium, sometimes the audio overlaps or even gets muted. This situation occurs using Chromium for desktop and Google Chrome for mobile. If you can, I would recommend you to test the code using Firefox to see if this issue persists. Meanwhile, I will try to find a solution to this issue. |
This issue can probably be the same as #2. |
I've checked Firefox; works fine. I think this is an issue with Chromium/Chrome/Brave. This needs some more investigation. 🤔🕵️ |
Probably. I think this can be a missing |
Hello, @burntcarrot. I reviewed the code again and I noted that the issue for the audio getting muted in Chromium got solved when I used only one Previously, each of the functions The last commit I did, e6a9e43, now creates the global variable I have not seen an issue of audio overlapping again, so I want to know if this commit fixes the issue you reported. Maybe this also fixes #2? Just note that if you use the deployment from Vercel, try to hard refresh the page. Some times the browser uses a version of the code it has cached previously. |
Yeah, this seems better. Thanks for the fix!
I don't have iOS/Safari with me, but I can ask someone to test it out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Just some tiny nitpicks.
Sure, I will make those changes. |
@f1redr4g0n Merged to main, and works with main deployment. Thanks for the fix! |
Hello, @burntcarrot. I did some changes to the
script.js
file to create random intervals in the speech and make it sounds more natural (#8). I also made changes to JSDocs to make it matches to current state of the code and changes to make it more easier to edit. Here is a brief of the changes I did:add
//@ts-check
at the top of the code, so code editors likeVisual Studio Code
orneovim
can interpret errors, just as if you were using Typescript.remove the
writeDialogueText
and renamespeak
functions. Now the writing to the$dialogueText
is together with thespeak
functionality in the functionspeakAndWriteDialogueText
at the end of the file. This was made so the changes made by the random intervals could be easily set for both operations.add
randomIntervalsInMilliseconds
variable to hold the sums of all random intervals added to the timeouts of thespeakAndWriteToDialogueText
function. This is needed to calculate the timeouts properly.add
trimAndRemoveExtraWhiteSpaces
function to remove the white spaces that are at the start and end of a text, as well extra white spaces that have been inserted between the words. This function is, now, used by thegetInputText
to treat the input text and avoid long random intervals if the user inserts too much white spaces.add
addRandomIntervalInMilliseconds
function to add random intervals, in milliseconds, to therandomIntervalsInMilliseconds
variable. This function is used by thespeakAndWriteDialogueText
whenever there is a white space.The random interval used is inversely proportional to the interval chosen by the user, which means:
This makes the voices sound more natural.
add
cancelRandomIntervals
function to reset the variablerandomIntervalsInMilliseconds
to zero. This functions just exists to keep the code consistent in the style adopted in thespeakAndWriteDialogueText
function.fix typo in JSDocs and code: change
miliseconds
tomilliseconds
.