-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Generate AI Transcription from WP Backend #1438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AhmarZaidi
wants to merge
7
commits into
develop
Choose a base branch
from
feat/1211-wp-backend-ai-transcriptions
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2ca4275
Add AI transcript feature
AhmarZaidi 2e9a02c
Add captions to editor player
AhmarZaidi 1c37815
Fix captions duplication on frontend
AhmarZaidi 8837847
Update icon import as react component
AhmarZaidi 502ad34
Fix duplication track check logic
AhmarZaidi 218e3de
Fix github bot suggestions
AhmarZaidi 4865e7d
PR Feedback
AhmarZaidi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
136 changes: 136 additions & 0 deletions
136
assets/src/blocks/godam-player/components/AITranscription.js
This file contains hidden or 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,136 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { useState } from '@wordpress/element'; | ||
| import { BaseControl, Button, Spinner, Notice } from '@wordpress/components'; | ||
| import { __ } from '@wordpress/i18n'; | ||
| import apiFetch from '@wordpress/api-fetch'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { ReactComponent as TranscriptIcon } from '../../../images/ai-transcript.svg'; | ||
|
|
||
| /** | ||
| * AI Transcription component for GoDAM video block. | ||
| * | ||
| * @param {Object} props Component props. | ||
| * @param {number} props.attachmentId The attachment ID. | ||
| * @param {number} props.instanceId The instance ID for unique control IDs. | ||
| * @param {boolean} props.hasTranscription Whether transcription already exists. | ||
| * @param {Function} props.onTranscriptionComplete Callback when transcription is generated. | ||
| * | ||
| * @return {JSX.Element} The AI Transcription component. | ||
| */ | ||
| export default function AITranscription( { | ||
| attachmentId, | ||
| instanceId, | ||
| hasTranscription = false, | ||
| onTranscriptionComplete, | ||
| } ) { | ||
| const [ isLoading, setIsLoading ] = useState( false ); | ||
| const [ notice, setNotice ] = useState( null ); | ||
|
|
||
| /** | ||
| * Handle generate transcription button click. | ||
| */ | ||
| const handleGenerateTranscription = async () => { | ||
| setIsLoading( true ); | ||
| setNotice( null ); | ||
|
|
||
| try { | ||
| const response = await apiFetch( { | ||
| path: '/godam/v1/ai-transcription/process', | ||
| method: 'POST', | ||
| data: { | ||
| attachment_id: attachmentId, | ||
| }, | ||
| } ); | ||
|
|
||
| if ( response.success ) { | ||
| // Call the callback to update tracks in parent component | ||
| if ( onTranscriptionComplete ) { | ||
| await onTranscriptionComplete(); | ||
| } | ||
| } else { | ||
| throw new Error( | ||
| response.message || | ||
| __( 'Failed to generate transcription.', 'godam' ), | ||
| ); | ||
| } | ||
| } catch ( error ) { | ||
| setNotice( { | ||
| type: 'error', | ||
| message: | ||
| error.message || | ||
| __( 'An error occurred while generating transcription.', 'godam' ), | ||
| } ); | ||
| } finally { | ||
| setIsLoading( false ); | ||
| } | ||
| }; | ||
|
|
||
| // Don't show anything if attachment ID is invalid. | ||
| if ( ! attachmentId || isNaN( Number( attachmentId ) ) ) { | ||
| return null; | ||
| } | ||
AhmarZaidi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| let buttonLabel = __( 'Generate AI Transcription', 'godam' ); | ||
| if ( isLoading ) { | ||
| buttonLabel = __( 'Generating…', 'godam' ); | ||
| } else if ( hasTranscription ) { | ||
| buttonLabel = __( 'Transcription Generated', 'godam' ); | ||
| } | ||
|
|
||
| const helpText = __( | ||
| 'Generate AI-powered captions for the video. Once generated, captions will be available automatically in the player.', | ||
| 'godam', | ||
| ); | ||
|
|
||
| const isButtonDisabled = hasTranscription || isLoading; | ||
|
|
||
| return ( | ||
| <BaseControl | ||
| id={ `video-block__ai-transcription-${ instanceId }` } | ||
| label={ __( 'AI Transcription', 'godam' ) } | ||
| help={ helpText } | ||
| __nextHasNoMarginBottom | ||
| > | ||
| <div className="ai-transcription-control__content"> | ||
| <Button | ||
| __next40pxDefaultSize | ||
| variant="primary" | ||
| onClick={ handleGenerateTranscription } | ||
| disabled={ isButtonDisabled } | ||
| icon={ isLoading && <Spinner /> } | ||
| isBusy={ isLoading } | ||
| > | ||
| <span className="ai-transcription-control__button-content"> | ||
| { buttonLabel } | ||
| <TranscriptIcon | ||
| aria-label={ __( 'AI transcription icon', 'godam' ) } | ||
| role="img" | ||
| className={ | ||
| `ai-transcription-control__icon` + | ||
| ( isButtonDisabled | ||
| ? ' ai-transcription-control__icon--disabled' | ||
| : '' ) | ||
| } | ||
| /> | ||
| </span> | ||
| </Button> | ||
|
|
||
| { notice && ( | ||
| <div className="ai-transcription-control__notice-wrapper"> | ||
| <Notice | ||
| status={ notice.type } | ||
| isDismissible={ false } | ||
| > | ||
| { notice.message } | ||
| </Notice> | ||
| </div> | ||
| ) } | ||
| </div> | ||
| </BaseControl> | ||
| ); | ||
| } | ||
This file contains hidden or 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 hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.