Comments (6)
I don't understand your point. Could you explain it better and add some code samples of what you have in mind?
Thanks!
from subtitle.js.
Yep, for example, I would like this :
7
00:00:13,926 --> 00:00:15,537
I don't know
what happened to you,
8
00:00:15,580 --> 00:00:16,668
but I'll find out.
(as SRT)
To become :
[
{
"key": 7,
"start": "1970-01-01T00:00:13.926Z",
"end": "1970-01-01T00:00:15.537Z",
"text": "I don't know\nwhat happened to you,"
},
{
"key": 8,
"start": "1970-01-01T00:00:15.580Z",
"end": "1970-01-01T00:00:16.668Z",
"text": "but I'll find out."
}
]
(as Subtitle
objects)
Then :
{
"subtitles": [
{
"key": 7,
"start": "1970-01-01T00:00:13.926Z",
"end": "1970-01-01T00:00:15.537Z",
"text": "I don't know\nwhat happened to you,"
},
{
"key": 8,
"start": "1970-01-01T00:00:15.580Z",
"end": "1970-01-01T00:00:16.668Z",
"text": "but I'll find out."
}
],
"text": "I don't know what happened to you, but I'll find out."
}
(as Sentence
object)
Then, I'm able to make a translation, for example I don't know what happened to you, but I'll find out.
in english becomes J'ignore ce qui vous est arrivé, mais je le découvrirai.
in french :
{
"subtitles": [
{
"key": 7,
"start": "1970-01-01T00:00:13.926Z",
"end": "1970-01-01T00:00:15.537Z",
"text": "J'ignore ce qu'il\nvous est arrivé,"
},
{
"key": 8,
"start": "1970-01-01T00:00:15.580Z",
"end": "1970-01-01T00:00:16.668Z",
"text": "mais je le découvrirai."
}
],
"text": "J'ignore ce qu'il vous est arrivé, mais je le découvrirai."
}
Then I reverse the conversion to individual subtitles :
[
{
"key": 7,
"start": "1970-01-01T00:00:13.926Z",
"end": "1970-01-01T00:00:15.537Z",
"text": "J'ignore ce qu'il\nvous est arrivé,"
},
{
"key": 8,
"start": "1970-01-01T00:00:15.580Z",
"end": "1970-01-01T00:00:16.668Z",
"text": "mais je le découvrirai."
}
]
And finaly, to SRT :
7
00:00:13,926 --> 00:00:15,537
J'ignore ce qui vous est arrivé,
8
00:00:15,580 --> 00:00:16,668
mais je le découvrirai.
The purpose of this process is to retrieve the full context while translating, instead of just doing line-by-line.
Thanks
from subtitle.js.
But how would I detect the sentences? Through punctuation?
from subtitle.js.
Yep
from subtitle.js.
Hey, any news on this ? Thanks
from subtitle.js.
I don't think that this feature is in the scope of this module. You can create your own function to modify the array. It could be something like this:
const data = [
{
"key": 7,
"start": "1970-01-01T00:00:13.926Z",
"end": "1970-01-01T00:00:15.537Z",
"text": "I don't know\nwhat happened to you,"
},
{
"key": 8,
"start": "1970-01-01T00:00:15.580Z",
"end": "1970-01-01T00:00:16.668Z",
"text": "but I'll find out."
}
]
function getSentences (subtitles) {
return subtitles.reduce((memo, value, index) => {
if (memo.openSentence) {
memo.data[index - 1].subtitles.push(value)
memo.data[index - 1].text += ' ' + value.text
} else {
memo.data.push({
subtitles: [ value ],
text: value.text
})
}
memo.openSentence = !isCompleteSentence(value.text)
return memo
}, { data: [], openSentence: false }).data
}
function isCompleteSentence (text) {
// you probably want to check other punctuations like ?, !, etc.
return text.endsWith('.')
}
getSentences(data)
from subtitle.js.
Related Issues (20)
- Typescript support HOT 4
- support lrc file HOT 1
- problem with Internet explorer HOT 1
- Error in parsing some srt files HOT 1
- Not transpiled `module` entry in `package.json` overrides `main` HOT 2
- How to add background or color in subtitle ? HOT 1
- Lookup by timecode? HOT 2
- parse() inserts 'undefined' for empty ?first lines in captions
- srt to vtt ? HOT 3
- Support VTT comments HOT 2
- Add parseSettings
- Add formatSettings HOT 2
- Add support for identifers HOT 2
- timestamp parse error HOT 2
- Support single digit timestamps HOT 1
- .
- Parsing WebVTT cue-identifiers fails HOT 1
- parseSync doesn't load in browser when built with vite and ESM HOT 3
- Support for setting an initial index on `stringify()` and `stringifySynch()`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from subtitle.js.