Skip to content

Commit

Permalink
list source lang
Browse files Browse the repository at this point in the history
  • Loading branch information
aynsix committed Nov 3, 2023
1 parent c6bca4b commit cc8c1f6
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 58 deletions.
42 changes: 40 additions & 2 deletions lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ public function autoSubtitleAction(Request $request)
new RecordAutoSubtitleEvent(
$record,
$request->request->get("subtitle_language_source"),
$request->request->get("meta_struct_id_source"),
json_decode($request->request->get("subtitle_destination"), true)
)
);
Expand Down Expand Up @@ -618,7 +617,8 @@ public function videoEditorAction(Request $request)
'videoEditorConfig' => $conf->get(['video-editor']),
'metadatas' => $metadatas,
'JSonFields' => json_encode($JSFields),
'videoTextTrackFields' => $videoTextTrackFields
'videoTextTrackFields' => $videoTextTrackFields,
'languages' => $this->languageList()
]);
}

Expand All @@ -633,4 +633,42 @@ private function isPhysicallyPresent(record_adapter $record, $subdefName)

return false;
}

private function languageList()
{
return [
'af-ZA' => 'af-ZA Afrikaans (South Africa)', 'am-ET' => 'am-ET Amharic (Ethiopia)',
'ar-DZ' => 'ar-DZ Arabic (Algeria)', 'ar-BH' => 'ar-BH Arabic (Bahrain)',
'ar-EG' => 'ar-EG Arabic (Egypt)', 'ar-IQ' => 'ar-IQ Arabic (Iraq)',
'ar-IL' => 'ar-IL Arabic (Israel)', 'ar-YE' => 'ar-YE Arabic (Yemen)',
'eu-ES' => 'eu-ES Basque (Spain)', 'bn-BD' => 'bn-BD Bengali (Bangladesh)',
'bn-IN' => 'bn-IN Bengali (India)', 'bg-BG' => 'bg-BG Bulgarian (Bulgaria)',
'ca-ES' => 'ca-ES Catalan (Spain)', 'yue-Hant-HK' => 'yue-Hant-HK Chinese, Cantonese (Traditional, Hong Kong)',
'cmn-Hans-CN' => 'cmn-Hans-CN Chinese, Mandarin (Simplified, China)', 'hr-HR' => 'hr-HR Croatian (Croatia)',
'cs-CZ' => 'cs-CZ Czech (Czech Republic)', 'da-DK' => 'da-DK Danish (Denmark)',
'nl-NL' => 'nl-NL Dutch (Netherlands)', 'nl-BE' => 'nl-BE Dutch (Belgium)',
'en-AU' => 'en-AU English (Australia)', 'en-CA' => 'en-CA English (Canada)',
'en-GB' => 'en-GB English (United Kingdom)', 'en-US' => 'en-US English (United States)',
'fr-CA' => 'fr-CA French (Canada)', 'fr-FR' => 'fr-FR French (France)',
'fr-BE' => 'fr-BE French (Belgium)', 'fr-CH' => 'fr-CH French (Switzerland)',
'ka-GE' => 'ka-GE Georgian (Georgia)', 'de-DE' => 'de-DE German (Germany)',
'el-GR' => 'el-GR Greek (Greece)', 'he-IL' => 'he-IL Hebrew (Israel)',
'hi-IN' => 'hi-IN Hindi (India)', 'hu-HU' => 'hu-HU Hungarian (Hungary)',
'is-IS' => 'is-IS Icelandic (Iceland)', 'id-ID' => 'id-ID Indonesian (Indonesia)',
'it-IT' => 'it-IT Italian (Italy)', 'ja-JP' => 'ja-JP Japanese (Japan)',
'ko-KR' => 'ko-KR Korean (South Korea)', 'lo-LA' => 'lo-LA Lao (Laos)',
'lt-LT' => 'lt-LT Lithuanian (Lithuania)', 'ms-MY' => 'ms-MY Malay (Malaysia)',
'ne-NP' => 'ne-NP Nepali (Nepal)', 'nb-NO' => 'nb-NO Norwegian Bokmål (Norway)',
'pl-PL' => 'pl-PL Polish (Poland)', 'pt-BR' => 'pt-BR Portuguese (Brazil)',
'pt-PT' => 'pt-PT Portuguese (Portugal)', 'ro-RO' => 'ro-RO Romanian (Romania)',
'ru-RU' => 'ru-RU Russian (Russia)', 'sr-RS' => 'sr-RS Serbian (Serbia)',
'sk-SK' => 'sk-SK Slovak (Slovakia)', 'sl-SI' => 'sl-SI Slovenian (Slovenia)',
'es-ES' => 'es-ES Spanish (Spain)', 'sv-SE' => 'sv-SE Swedish (Sweden)',
'th-TH' => 'th-TH Thai (Thailand)', 'tr-TR' => 'tr-TR Turkish (Turkey)',
'uk-UA' => 'uk-UA Ukrainian (Ukraine)', 'vi-VN' => 'vi-VN Vietnamese (Vietnam)',
'et-EE' => 'et-EE Estonian (Estonia)', 'mn-MN' => 'mn-MN Mongolian (Mongolia)',
'uz-UZ' => 'uz-UZ Uzbek (Uzbekistan)'

];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ class RecordAutoSubtitleEvent extends RecordEvent
public function __construct(
RecordInterface $record,
$languageSource,
$metaStructureIdSource,
$languageDestination
)
{
parent::__construct($record);

$this->languageSource = $languageSource;
$this->metaStructureIdSource = $metaStructureIdSource;
$this->languageDestination = $languageDestination;
}

Expand All @@ -30,11 +28,6 @@ public function getLanguageSource()
return $this->languageSource;
}

public function getMetaStructureIdSource()
{
return $this->metaStructureIdSource;
}

public function getLanguageDestination()
{
return $this->languageDestination;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function onRecordAutoSubtitle(RecordAutoSubtitleEvent $event)
"databoxId" => $event->getRecord()->getDataboxId(),
"recordId" => $event->getRecord()->getRecordId(),
"languageSource" => $event->getLanguageSource(),
"metaStructureIdSource" => $event->getMetaStructureIdSource(),
"languageDestination" => $event->getLanguageDestination(),
"type" => MessagePublisher::SUBTITLE_TYPE // used to specify the final Q to publish message
];
Expand Down
92 changes: 49 additions & 43 deletions lib/Alchemy/Phrasea/WorkerManager/Worker/SubtitleWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ public function process(array $payload)
$this->extension = 'vtt';
}

$languageSource = $this->getLanguageFormat($payload['languageSource']);

$record = $this->getApplicationBox()->get_databox($payload['databoxId'])->get_record($payload['recordId']);

// if subdef_source not set, by default use the preview permalink
Expand Down Expand Up @@ -145,20 +143,28 @@ public function process(array $payload)

// create a transcription

$responseTranscription = $this->happyscribeClient->post('https://www.happyscribe.com/api/v1/transcriptions', [
'headers' => [
'Authorization' => 'Bearer '. $this->happyscribeToken
],
'json' => [
'transcription' => [
'name' => $record->get_title(),
'is_subtitle' => true,
'language' => $languageSource,
'organization_id' => $organizationId,
'tmp_url' => $tmpUrl
try {
$responseTranscription = $this->happyscribeClient->post('https://www.happyscribe.com/api/v1/transcriptions', [
'headers' => [
'Authorization' => 'Bearer '. $this->happyscribeToken
],
'json' => [
'transcription' => [
'name' => $record->get_title(),
'is_subtitle' => true,
'language' => $payload['languageSource'],
'organization_id' => $organizationId,
'tmp_url' => $tmpUrl
]
]
]
]);
]);

} catch (\Exception $e) {
$this->logger->error("error when creating transcript : " . $e->getMessage());
$this->jobFinished();

return 0;
}

if ($responseTranscription->getStatusCode() !== 200) {
$this->logger->error("error when creating transcript,response status : ". $responseTranscription->getStatusCode());
Expand Down Expand Up @@ -212,7 +218,7 @@ public function process(array $payload)
foreach ($payload['languageDestination'] as $language => $metaStructureIdDestination) {
$languageDestination = strtolower($language);

if (strtolower($payload['languageSource']) == $languageDestination) {
if ($this->getTargetLanguageByCode($payload['languageSource']) == $languageDestination) {
$metadatas[] = [
'meta_struct_id' => (int)$metaStructureIdDestination,
'meta_id' => '',
Expand Down Expand Up @@ -244,9 +250,9 @@ public function process(array $payload)

// delete transcription

foreach ($this->transcriptionsId as $transcriptionId) {
$this->deleteTranscription($transcriptionId);
}
// foreach ($this->transcriptionsId as $transcriptionId) {
// $this->deleteTranscription($transcriptionId);
// }

$this->jobFinished();

Expand Down Expand Up @@ -277,19 +283,6 @@ private function jobFinished()
}
}

private function getLanguageFormat($language)
{
switch ($language) {
case 'En':
return 'en-GB';
case 'De':
return 'de-DE';
case 'Fr':
default:
return 'fr-FR';
}
}

private function isRemoteFileExist($fileUrl)
{
$client = new Client();
Expand Down Expand Up @@ -384,23 +377,29 @@ private function exportTranscription($transcriptionId)

$transcriptContent = file_get_contents($subtitleTranscriptTemporaryFile);

$transcriptContent = preg_replace('/WEBVTT/', 'WEBVTT - with cue identifier', $transcriptContent, 1);

return $transcriptContent;
}

private function translate($sourceTranscriptionId, $targetLanguage)
{
// translate
$resTranslate = $this->happyscribeClient->post('https://www.happyscribe.com/api/v1/task/transcription_translation', [
'headers' => [
'Authorization' => 'Bearer ' . $this->happyscribeToken
],
'json' => [
'source_transcription_id' => $sourceTranscriptionId,
'target_language' => strtolower($targetLanguage)
]
]);
try {
$resTranslate = $this->happyscribeClient->post('https://www.happyscribe.com/api/v1/task/transcription_translation', [
'headers' => [
'Authorization' => 'Bearer ' . $this->happyscribeToken
],
'json' => [
'source_transcription_id' => $sourceTranscriptionId,
'target_language' => strtolower($targetLanguage)
]
]);
} catch (\Exception $e) {
$this->logger->error("error when translate : ". $e->getMessage());
$this->jobFinished();

return 0;
}


if ($resTranslate->getStatusCode() !== 200) {
$this->logger->error("error when translate, response status : ". $resTranslate->getStatusCode());
Expand Down Expand Up @@ -470,4 +469,11 @@ private function deleteTranscription($transcriptionId)
]
]);
}

private function getTargetLanguageByCode($code)
{
$t = explode('-', $code);

return $t[0];
}
}
9 changes: 4 additions & 5 deletions templates/web/prod/actions/Tools/videoEditor.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
<p class="item">
<label>{{ "prod:videoeditor:subtitleRequestTab:label:: Provider" | trans }}</label>
<select name="subtitleProvider" id="subtitle_provider">
<option value="Ginger">Ginger</option>
<option value="Ginger">Happyscribe (beta)</option>
</select>
</p>
<p class="item">
Expand All @@ -241,8 +241,8 @@
<p class="item">
<label>{{ "prod:videoeditor:subtitleRequestTab:label:: Source Audio language" | trans }}</label>
<select name="subtitle_language_source" id="subtitle_language_source">
{% for videoTextTrackField in videoTextTrackFields %}
<option value="{{ videoTextTrackField.meta_struct_id}}">{{ videoTextTrackField.label}}</option>
{% for code,language in languages | sort %}
<option value="{{ code }}" {% if code == 'fr-FR' %} selected {% endif %}>{{ language }}</option>
{% endfor %}
</select>
</p>
Expand Down Expand Up @@ -373,8 +373,7 @@
data: {
databox_id: {{ record.getDataboxId }},
record_id: {{ record.getRecordId }},
subtitle_language_source: $('#subtitle_language_source option:selected').text(),
meta_struct_id_source: $('#subtitle_language_source').val(),
subtitle_language_source: $('#subtitle_language_source').val(),
subtitle_destination: JSON.stringify(destination),
},
success: function success(data) {
Expand Down

0 comments on commit cc8c1f6

Please sign in to comment.