Giter VIP home page Giter VIP logo

Comments (6)

gsantiago avatar gsantiago commented on May 26, 2024

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.

KaKi87 avatar KaKi87 commented on May 26, 2024

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.

gsantiago avatar gsantiago commented on May 26, 2024

But how would I detect the sentences? Through punctuation?

from subtitle.js.

KaKi87 avatar KaKi87 commented on May 26, 2024

Yep

from subtitle.js.

KaKi87 avatar KaKi87 commented on May 26, 2024

Hey, any news on this ? Thanks

from subtitle.js.

gsantiago avatar gsantiago commented on May 26, 2024

@KaKi87

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.