-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
e3946a9
commit 31492fa
Showing
13 changed files
with
243 additions
and
46 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import axios from 'axios'; | ||
|
||
export const translateLyrics = async ( | ||
originalLyrics: string, | ||
translationApiKey: string, | ||
translationApiProvider: string | null, | ||
translationTargetLanguage: string | null, | ||
) => { | ||
let TranslatedText = ''; | ||
if (translationApiProvider === 'Microsoft Azure') { | ||
try { | ||
const response = await axios({ | ||
data: [ | ||
{ | ||
Text: originalLyrics, | ||
}, | ||
], | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Ocp-Apim-Subscription-Key': translationApiKey, | ||
}, | ||
method: 'post', | ||
url: `https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=${translationTargetLanguage as string}`, | ||
}); | ||
TranslatedText = response.data[0].translations[0].text; | ||
} catch (e) { | ||
console.error('Microsoft Azure translate request got an error!', e); | ||
return null; | ||
} | ||
} else if (translationApiProvider === 'Google Cloud') { | ||
try { | ||
const response = await axios({ | ||
data: { | ||
format: 'text', | ||
q: originalLyrics, | ||
}, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
method: 'post', | ||
url: `https://translation.googleapis.com/language/translate/v2?target=${translationTargetLanguage as string}&key=${translationApiKey}`, | ||
}); | ||
TranslatedText = response.data.data.translations[0].translatedText; | ||
} catch (e) { | ||
console.error('Google Cloud translate request got an error!', e); | ||
return null; | ||
} | ||
} | ||
return TranslatedText; | ||
}; |
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
Oops, something went wrong.