Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get speaker notes from Google Slides by API?

I want to get speaker notes from Google Slides by API, but I could not find any fields for speaker notes.

For reference: Method: presentations.pages.get

What would be a good way to do this?

like image 461
Tomoyuki Hisada Avatar asked Nov 21 '16 04:11

Tomoyuki Hisada


People also ask

How do I extract speaker notes from Google Slides?

To get started, open your deck in Google Slides, go to the Addons menu and choose Creator Studio. Next, select the Speaker Notes menu and you'll see just the speaker notes of all slides in a popup window that you can download and print.

Does Google Slides have an API?

Using the APIMany of the features that make Google Slides so successful are available through the API. This lets you access and update presentations programatically, integrating data from various sources and producing finished presentations in a fraction of the time.

How do you convert Google Slides to notes?

Save text or image as a note On your computer, open a document or presentation in Google Docs or Google Slides. Highlight and right-click the text or image you want to save as a note. From the menu that appears, click Save to Keep.


2 Answers

Support for speaker notes is now available in the Slides API v1. Documentation is here: https://developers.google.com/slides/how-tos/notes

like image 76
Maurice Codik Avatar answered Oct 18 '22 01:10

Maurice Codik


In the absence of the API, I wouldn't suggest this is a good way of doing it. In fact it is horrible. But here it is. If you absolutely had to do it. It is likely a bit flakey too.

Steps are:

  1. Export the presentation, via the Drive API, as a PowerPoint .pptx file
  2. Unpack the file - it is a zip file containing a directory structure with XML files in.
  3. Identify the speaker notes files and process them as per your requirement (e.g. extract all text, or work on the XML etc).

Ugly right? Here's an example in Apps Script:

  1. Enable Drive API in Advanced Services within your script (Resources > Advanced Google Services).

    function example() {
      // Print out the speaker notes
      Logger.log(getNotes('123abc......asd'));
    }
    
    // Returns an array of strings, one string per slide
    // representing the speaker notes.
    function getNotes(presentationId) {
      //DriveApp.createFile();
      var notesRegex = /ppt\/notesSlides\/notesSlide\d+\.xml/;
    
      var url = 'https://www.googleapis.com/drive/v2/files/' + presentationId +
        '/export?mimeType=application%2Fvnd.openxmlformats-officedocument.presentationml.presentation';
      var options = {
        headers: {
          Authorization : 'Bearer ' + ScriptApp.getOAuthToken()
        }
      };
      var response = UrlFetchApp.fetch(url, options);
    
      var zipBlob = Utilities.newBlob(response.getContent(), 'application/zip');
      var data = Utilities.unzip(zipBlob);
    
      var notes = [];
      for (var i = 0; i < data.length; i++) {
        if (notesRegex.test(data[i].getName())) {
    
          // Example simply extracts text from speaker notes
          // You could do something more complex.
          notes.push(extractTextFromXml(data[i].getDataAsString()));
        }
      }
      return notes;
    }
    
    function extractTextFromXml(xml) {
      var doc = XmlService.parse(xml);
      var root = doc.getRootElement();
      var ns = root.getNamespace('a');
    
      var text = [];
    
      function walkNode(node) {
        if (node.getText()) {
          text.push(node.getText());
        }
        var children = node.getChildren();
        if (children.length) {
          children.forEach(function(child) {
            walkNode(child);
          });
        }
      }
      walkNode(root);
      return text.join('\n');
    }
    
like image 42
Bardy Avatar answered Oct 17 '22 23:10

Bardy