Skip to content

Commit

Permalink
filter out known fake #16
Browse files Browse the repository at this point in the history
  • Loading branch information
abrahamjuliot committed Dec 5, 2021
1 parent 23a8497 commit 7e63509
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions modules/voices.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,40 @@ export const getVoices = imports => {
return
}
success = true
const filterFirstOccurenceOfUniqueVoiceURIData = ({data, voiceURISet}) => data.filter(x => {
// https://github.com/brave/brave-core/blob/master/chromium_src/third_party/blink/renderer/modules/speech/speech_synthesis.cc#L41-L44
const knownFake = [
'Hubert',
'Vernon',
'Rudolph',
'Clayton',
'Irving',
'Wilson',
'Alva',
'Harley',
'Beauregard',
'Cleveland',
'Cecil',
'Reuben',
'Sylvester',
'Jasper'
]
const getTrustedData = ({data, voiceURISet}) => data.filter(x => {
const { voiceURI, name } = x
if (!voiceURISet.has(voiceURI)) {
voiceURISet.add(voiceURI)
return true
if (voiceURISet.has(voiceURI) && knownFake.includes(name)) {
sendToTrash(`speechSynthesis`, `'${name}' is a known fake name w/o a unique voiceURI`)
return false
}
sendToTrash(`speechSynthesis`, `'${name}' does not have a unique voiceURI`)
return false
voiceURISet.add(voiceURI)
return true
})

const dataUnique = filterFirstOccurenceOfUniqueVoiceURIData({ data, voiceURISet: new Set() })
const dataTrusted = getTrustedData({ data, voiceURISet: new Set() })

// https://wicg.github.io/speech-api/#speechsynthesisvoice-attributes
const local = dataUnique.filter(x => x.localService).map(x => x.name)
const remote = dataUnique.filter(x => !x.localService).map(x => x.name)
const languages = [...new Set(dataUnique.map(x => x.lang))]
const defaults = dataUnique.filter(x => x.default).map(x => x.name)
const local = dataTrusted.filter(x => x.localService).map(x => x.name)
const remote = dataTrusted.filter(x => !x.localService).map(x => x.name)
const languages = [...new Set(dataTrusted.map(x => x.lang))]
const defaults = dataTrusted.filter(x => x.default).map(x => x.name)

logTestResult({ start, test: 'speech', passed: true })
return resolve({
Expand Down

0 comments on commit 7e63509

Please sign in to comment.