Quick and Easily Remove Timestamps and Spaces From Transcripts From Youtube Videos

Quick and Easily Remove Timestamps and Spaces From Transcripts From Youtube Videos

Do you ever copy text from videos or other sources and find that it includes timestamps and unnecessary spacing and line breaks? It can be frustrating to manually clean up the text to make it readable. With this nifty Google Docs script, you can easily format the text into nice paragraphs without changing the words. Simply paste the text and run the script to remove the timestamps, extra spaces, and lines. Your text will look professional and easy to read in no time.  No coding is necessary!

Step-by-step Instructions For Removing Timestamps

Follows these easy steps for implementing code to format and clean up text in Google Docs:

  1. Copy the transcript text from the YouTube video you want to format and clean up.
  1. Open Google Docs and create a new document, or open an existing document where you want to paste the formatted text.
  1. From the menu bar, select “Tools” and then “Script Editor”. This will open a new window with the Google Apps Script editor.
  1. In the new window, delete any existing code and paste the code provided below.  First, be sure to delete any other code in there.  You may have to give Google permission a couple of times and run it again before it works:
function cleanTranscript() {
  var doc = DocumentApp.getActiveDocument();
  var body = doc.getBody();
  var text = body.getText();
  // Remove timestamps
  text = text.replace(/^\d+:\d+\s*/gm, '');
  // Remove extra spaces and newlines
  text = text.replace(/\s+/g, ' ').trim();
  // Format into paragraphs
  var paragraphs = text.split('. ');
  var formattedText = '';
  for (var i = 0; i < paragraphs.length; i++) {
    var sentence = paragraphs[i].trim();
    if (sentence !== '') {
      formattedText += (i === 0 ? '' : ' ') + sentence + '.';
  // Insert the formatted text into the document
  body.editAsText().insertText(0, formattedText);

This is what the google Apps Script editor looks like.

  1. Save the script by clicking “File” and then “Save” and the “Run”
  2. Now that the formatting is complete, it should look like this.  Review the document to ensure the text is properly formatted and all timestamps and unnecessary spaces and line breaks have been removed.
  1. Save the document.

That’s it! With these instructions, you should be able to easily format and clean up text in Google.  

Warning:  I am not a coder and know very little about it but I am very curious.  Which…can be a good thing because of this I am patient and can explain these steps in an easy-to-understand novice-like manner.   These steps and code were generated by ChatGPT 4.0, and hopefully, this will help some other Gen Xer out there.  If the code doesn’t work then try getting help from ChatGPT and asking it to rewrite it for your own purposes.  Next time I will be giving you some helpful tips when interacting with ChatGPT 4.0.

Leave a Reply

Your email address will not be published. Required fields are marked *