mirror of
https://github.com/acid-info/logos-press-engine.git
synced 2025-02-23 22:58:08 +00:00
feat: implement transcription
This commit is contained in:
parent
67c3336478
commit
2257ea9966
@ -2,6 +2,7 @@ import {
|
|||||||
extractClassFromFirstTag,
|
extractClassFromFirstTag,
|
||||||
extractIdFromFirstTag,
|
extractIdFromFirstTag,
|
||||||
} from '@/utils/html.utils'
|
} from '@/utils/html.utils'
|
||||||
|
import { lsdUtils } from '@/utils/lsd.utils'
|
||||||
import { parseTranscriptionText } from '@/utils/string.utils'
|
import { parseTranscriptionText } from '@/utils/string.utils'
|
||||||
import { Typography } from '@acid-info/lsd-react'
|
import { Typography } from '@acid-info/lsd-react'
|
||||||
import styled from '@emotion/styled'
|
import styled from '@emotion/styled'
|
||||||
@ -22,24 +23,30 @@ export const RenderEpisodeBlock = ({
|
|||||||
|
|
||||||
if (isYoutube) return <ReactPlayer url={youtubeLink[0]} />
|
if (isYoutube) return <ReactPlayer url={youtubeLink[0]} />
|
||||||
else {
|
else {
|
||||||
const { time, transcript } = parseTranscriptionText(block.text)
|
const { time, speaker, transcript } = parseTranscriptionText(block.text)
|
||||||
|
|
||||||
return (
|
return transcript?.length ? (
|
||||||
<TranscriptionItem variant="body1" component={'p'}>
|
<TranscriptionItem variant="body1" component={'div'}>
|
||||||
{time && (
|
{time && (
|
||||||
<>
|
<>
|
||||||
<span>{time}</span>
|
<TranscriptInfo variant="body2">[{time}]</TranscriptInfo>
|
||||||
<span>|</span>
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<span
|
<Transcript>
|
||||||
|
<TranscriptInfo variant="body2" component="p">
|
||||||
|
{speaker}
|
||||||
|
</TranscriptInfo>
|
||||||
|
<TranscriptText
|
||||||
className={extractClassFromFirstTag(block.html) || ''}
|
className={extractClassFromFirstTag(block.html) || ''}
|
||||||
id={extractIdFromFirstTag(block.html) || `p-${block.id}`}
|
id={extractIdFromFirstTag(block.html) || `p-${block.id}`}
|
||||||
|
variant="body1"
|
||||||
|
component="p"
|
||||||
>
|
>
|
||||||
{transcript}
|
{transcript}
|
||||||
</span>
|
</TranscriptText>
|
||||||
|
</Transcript>
|
||||||
</TranscriptionItem>
|
</TranscriptionItem>
|
||||||
)
|
) : null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,3 +55,23 @@ const TranscriptionItem = styled(Typography)`
|
|||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
gap: 12px;
|
gap: 12px;
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const TranscriptInfo = styled(Typography)`
|
||||||
|
${(props) => lsdUtils.breakpoint(props.theme, 'xs', 'down')} {
|
||||||
|
font-size: var(--lsd-body3-fontSize);
|
||||||
|
line-height: var(--lsd-body3-lineHeight);
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
const Transcript = styled.div`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
`
|
||||||
|
|
||||||
|
const TranscriptText = styled(Typography)`
|
||||||
|
${(props) => lsdUtils.breakpoint(props.theme, 'xs', 'down')} {
|
||||||
|
font-size: var(--lsd-body2-fontSize);
|
||||||
|
line-height: var(--lsd-body2-lineHeight);
|
||||||
|
}
|
||||||
|
`
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { lsdUtils } from '@/utils/lsd.utils'
|
|
||||||
import useWindowSize from '@/utils/ui.utils'
|
import useWindowSize from '@/utils/ui.utils'
|
||||||
import { Button } from '@acid-info/lsd-react'
|
import { Button } from '@acid-info/lsd-react'
|
||||||
import styled from '@emotion/styled'
|
import styled from '@emotion/styled'
|
||||||
@ -37,7 +36,7 @@ const EpisodeBlocks = ({ data }: Props) => {
|
|||||||
const BlocksContainer = styled.div<{ n: number }>`
|
const BlocksContainer = styled.div<{ n: number }>`
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 24px;
|
gap: 32px;
|
||||||
|
|
||||||
> *:nth-of-type(n + ${({ n }) => n + 1}) {
|
> *:nth-of-type(n + ${({ n }) => n + 1}) {
|
||||||
display: none;
|
display: none;
|
||||||
@ -48,10 +47,6 @@ const BlocksContainer = styled.div<{ n: number }>`
|
|||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
${(props) => lsdUtils.breakpoint(props.theme, 'sm', 'down')} {
|
|
||||||
gap: 16px;
|
|
||||||
}
|
|
||||||
`
|
`
|
||||||
const ShowButton = styled(Button)`
|
const ShowButton = styled(Button)`
|
||||||
margin-top: calc(var(--lsd-body2-lineHeight) * 1);
|
margin-top: calc(var(--lsd-body2-lineHeight) * 1);
|
||||||
|
@ -69,18 +69,38 @@ export function convertToIframe(url: string) {
|
|||||||
const removeFootnoteReferences = (text: string) =>
|
const removeFootnoteReferences = (text: string) =>
|
||||||
text.replaceAll(/\[\d+\]/g, '')
|
text.replaceAll(/\[\d+\]/g, '')
|
||||||
|
|
||||||
export const parseTranscriptionText = (text: string) => {
|
// export const parseTranscriptionText = (text: string) => {
|
||||||
const time = text.match(/^(\d{1,2}:?){2,3}/g)?.[0] ?? ''
|
// const time = text.match(/^(\d{1,2}:?){2,3}/g)?.[0] ?? ''
|
||||||
const transcript = removeFootnoteReferences(
|
// const transcript = removeFootnoteReferences(
|
||||||
time ? text.replace(time, '') : text,
|
// time ? text.replace(time, '') : text,
|
||||||
).trim()
|
// ).trim()
|
||||||
|
|
||||||
const parsedTime = time.endsWith(':') ? time.slice(0, -1) : time
|
// const parsedTime = time.endsWith(':') ? time.slice(0, -1) : time
|
||||||
const parsedTranscript = transcript.replace(/^(-|\||\s)*/, '')
|
// const parsedTranscript = transcript.replace(/^(-|\||\s)*/, '')
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// time: parsedTime,
|
||||||
|
// transcript: parsedTranscript,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
export function parseTranscriptionText(transcript: string) {
|
||||||
|
const regex = /\[(\d{2}:\d{2}:\d{2})\]\s*(.*?):\s*(.*)/
|
||||||
|
|
||||||
|
const match = transcript.match(regex)
|
||||||
|
|
||||||
|
if (!match) {
|
||||||
|
return {
|
||||||
|
time: '',
|
||||||
|
speaker: '',
|
||||||
|
transcript: '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
time: parsedTime,
|
time: match[1],
|
||||||
transcript: parsedTranscript,
|
speaker: match[2],
|
||||||
|
transcript: removeFootnoteReferences(match[3]).trim(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user