-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add known working language codes as exports
- Loading branch information
Nick Pierson
committed
Dec 10, 2020
1 parent
00c0d6b
commit aec0ae3
Showing
8 changed files
with
153 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
import { getAudioUrl, getAllAudioUrls } from './getAudioUrl'; | ||
import { getAudioBase64, getAllAudioBase64 } from './getAudioBase64'; | ||
import { getAudioUrl, getAllAudioUrls } from "./getAudioUrl"; | ||
import { getAudioBase64, getAllAudioBase64 } from "./getAudioBase64"; | ||
import languages from "./languages"; | ||
|
||
export { getAudioUrl, getAllAudioUrls, getAudioBase64, getAllAudioBase64 }; | ||
export { | ||
getAudioUrl, | ||
getAllAudioUrls, | ||
getAudioBase64, | ||
getAllAudioBase64, | ||
languages, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
export type Language = typeof languages[number]; | ||
export type LanguageCode = typeof languages[number]["code"]; | ||
export type LanguageName = typeof languages[number]["name"]; | ||
|
||
// prettier-ignore | ||
const languages = [ | ||
{ code: "af-ZA", name: "Afrikaans" }, | ||
{ code: "sq", name: "Albanian" }, | ||
{ code: "ar", name: "Arabic" }, | ||
{ code: "hy", name: "Armenian" }, | ||
{ code: "bn-BD", name: "Bengali (Bangladesh)" }, | ||
{ code: "bn-IN", name: "Bengali (India)" }, | ||
{ code: "bs", name: "Bosnian" }, | ||
{ code: "my", name: "Burmese (Myanmar)" }, | ||
{ code: "ca-ES", name: "Catalan" }, | ||
{ code: "cmn-Hant-TW", name: "Chinese" }, | ||
{ code: "hr-HR", name: "Croatian" }, | ||
{ code: "cs-CZ", name: "Czech" }, | ||
{ code: "da-DK", name: "Danish" }, | ||
{ code: "nl-NL", name: "Dutch" }, | ||
{ code: "en-AU", name: "English (Australia)" }, | ||
{ code: "en-GB", name: "English (United Kingdom)" }, | ||
{ code: "en-US", name: "English (United States)" }, | ||
{ code: "eo", name: "Esperanto" }, | ||
{ code: "et", name: "Estonian" }, | ||
{ code: "fil-PH", name: "Filipino" }, | ||
{ code: "fi-FI", name: "Finnish" }, | ||
{ code: "fr-FR", name: "French" }, | ||
{ code: "fr-CA", name: "French (Canada)" }, | ||
{ code: "de-DE", name: "German" }, | ||
{ code: "el-GR", name: "Greek" }, | ||
{ code: "gu", name: "Gujarati" }, | ||
{ code: "hi-IN", name: "Hindi" }, | ||
{ code: "hu-HU", name: "Hungarian" }, | ||
{ code: "is-IS", name: "Icelandic" }, | ||
{ code: "id-ID", name: "Indonesian" }, | ||
{ code: "it-IT", name: "Italian" }, | ||
{ code: "ja-JP", name: "Japanese (Japan)" }, | ||
{ code: "kn", name: "Kannada" }, | ||
{ code: "km", name: "Khmer" }, | ||
{ code: "ko-KR", name: "Korean" }, | ||
{ code: "la", name: "Latin" }, | ||
{ code: "lv", name: "Latvian" }, | ||
{ code: "mk", name: "Macedonian" }, | ||
{ code: "ml", name: "Malayalam" }, | ||
{ code: "mr", name: "Marathi" }, | ||
{ code: "ne", name: "Nepali" }, | ||
{ code: "nb-NO", name: "Norwegian" }, | ||
{ code: "pl-PL", name: "Polish" }, | ||
{ code: "pt-BR", name: "Portuguese" }, | ||
{ code: "ro-RO", name: "Romanian" }, | ||
{ code: "ru-RU", name: "Russian" }, | ||
{ code: "sr-RS", name: "Serbian" }, | ||
{ code: "si", name: "Sinhala" }, | ||
{ code: "sk-SK", name: "Slovak" }, | ||
{ code: "es-MX", name: "Spanish (Mexico)" }, | ||
{ code: "es-ES", name: "Spanish (Spain)" }, | ||
{ code: "sw", name: "Swahili" }, | ||
{ code: "sv-SE", name: "Swedish" }, | ||
{ code: "ta", name: "Tamil" }, | ||
{ code: "te", name: "Telugu" }, | ||
{ code: "th-TH", name: "Thai" }, | ||
{ code: "tr-TR", name: "Turkish" }, | ||
{ code: "uk-UA", name: "Ukrainian" }, | ||
{ code: "ur", name: "Urdu" }, | ||
{ code: "vi-VN", name: "Vietnamese" }, | ||
{ code: "cy", name: "Welsh" }, | ||
] as const; | ||
|
||
/** | ||
* find language from language code | ||
* | ||
* @param {string} code | ||
*/ | ||
const findByCode = (code: LanguageCode): Language | undefined => | ||
languages.find((l) => l.code === code); | ||
|
||
/** | ||
* find language from language name | ||
* | ||
* @param {string} name | ||
*/ | ||
const findByName = (name: LanguageName): Language | undefined => | ||
languages.find((l) => l.name === name); | ||
|
||
export default { | ||
get: () => languages, | ||
findByCode, | ||
findByName, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const googleTTS = require("../dist/index"); | ||
|
||
test("All voice codes are valid", async (done) => { | ||
const responses = googleTTS.languages.get().map((lang) => { | ||
return googleTTS | ||
.getAudioBase64("test", { lang: lang.code }) | ||
.catch((err) => { | ||
console.log("language code failed: " + lang.code); | ||
console.log(err); | ||
done.fail("language code failed: " + lang.code); | ||
}); | ||
}); | ||
|
||
await Promise.all(responses); | ||
done(); | ||
}, 10000); | ||
|
||
test("lookup by code", () => { | ||
const english = googleTTS.languages.findByCode("en-US"); | ||
expect(english.name).toBe("English (United States)"); | ||
}); | ||
|
||
test("lookup by name", () => { | ||
const english = googleTTS.languages.findByName("English (United States)"); | ||
expect(english.code).toBe("en-US"); | ||
}); |