kgn / Hark

An example Text to Speech App
186 stars 20 forks source link

Add automatic language detection #2

Closed ericrwolfe closed 11 years ago

ericrwolfe commented 11 years ago

Uses CFStringTokenizerCopyBestStringLanguage to determine the language of the text, then tries to update the voice of the AVSpeechUtterance accordingly.

kgn commented 11 years ago

This text was just read to me in a different language.

@erondu do u mean crutch or clutch?

Is there a way to know how accurate the guess is? Or do you think that the user should always be asked if they want the text spoken in a language that is not the current one?

ericrwolfe commented 11 years ago

Not with CFStringTokenizerCopyBestStringLanguage.

A previous version I was playing with used NSLinguisticTagger to manually loop through each word in the text, figure out the language for the word, and add the languages to an NSCountedSet to figure out the top language. Doing it that way you could essentially calculate the confidence or even switch languages mid-sentence if you wanted.

But the code was quite a bit more complex and probably much slower in practice, and NSLiguisticTagger was identifying all non-roman languages as "unknown", so I opted for the simpler solution above.

In what context was the text above read in a different language? By itself it was read in English for me (albeit quickly), but the pronunciation of @erondu was kind of odd, expectedly.

kgn commented 11 years ago

Ohh NSCountedSet that's a new one to me, awesome! The whole sentence was read in Slovak it turns out sk hehe

kgn commented 11 years ago

Thanks for the pull request, I pulled in the first part and we independently made the same later changes so the repo contains everything from this pull request so I'm gonna close this out.

jbrooksuk commented 11 years ago

Try reading "Hi" or "Hello". It's the wrong language for me.

kgn commented 11 years ago

Yeah the language detection is not 100% accurate. I'm thinking of adding an alert to ask the user if they want the text read in the detected language or their default language.

ericrwolfe commented 11 years ago

Good point. Might make sense only to do language detection for longer pieces of text.

jbrooksuk commented 11 years ago

I wonder how many words would generate 90%+ chance of selecting the right language? I would think 20 words is a good amount to start with.

Sent from my iPhone

On 27 Sep 2013, at 18:42, Eric Wolfe notifications@github.com wrote:

Good point. Might make sense only to do language detection for longer pieces of text.

— Reply to this email directly or view it on GitHub.

ericrwolfe commented 11 years ago

Rather than a more obtrusive alert, you could have a small button appear in the UI (perhaps in a toolbar above the keyboard) showing the detected language. Tapping it would let you select among the other available voices. Also, with this button the app could always just use the default language for short (i.e. less than a few words) pieces of text.

Although all of this might be overcomplicating the app for its generally simple use case :).

jbrooksuk commented 11 years ago

What's peculiar is that "I'm British. " is read in Male, British Siri and "I'm American. " is read in a foreign language.

Sent from my iPhone

On 27 Sep 2013, at 18:42, Eric Wolfe notifications@github.com wrote:

Good point. Might make sense only to do language detection for longer pieces of text.

— Reply to this email directly or view it on GitHub.

kgn commented 11 years ago

Haha that is funny