<%NOBLOCKOUTPUT%><%JAVASCRIPTASYNC:
```javascript
// Default to the page title
var wordToLookUp = encodeURIComponent(prompt('Enter word to lookup.',document.title));
// Get your API from https://dictionaryapi.com/register/index
var apiKey = 'Your API'
for(idx in data) {
var shortDef = data[idx].meta["app-shortdef"]
var ipa = "na"
if (data[idx].hwi["prs"] != undefined){
var prs = data[idx].hwi["prs"]
ipa = prs[0].ipa
if (prs[0].sound != undefined){
var sound = prs[0].sound["audio"]
var file = sound + ".mp3"
var subDir = sound[0] + "/"
var audioPath = audio + subDir + file
var embed = "{{audio: " + audioPath + "}}"
}
}
// Print the speech of word along with ipa pronunciation
await roam42.smartBlocks.activeWorkflow.outputAdditionalBlock(
shortDef["fl"] + " | / " + ipa + " / "
);
// Print URL of Merriam Learner's dictionary
await roam42.smartBlocks.activeWorkflow.outputAdditionalBlock(dicUrl);
// Definition of the word
await roam42.smartBlocks.activeWorkflow.outputAdditionalBlock(shortDef["def"]);
// Embed audio for the word
if (prs[0].sound != undefined){
await roam42.smartBlocks.activeWorkflow.outputAdditionalBlock(embed);
}
// Fetch only the first record
break;
}
return '';```
%>
📋 Describe the SmartBlock
Look up English words from Merriam Learner's dictionary. Page title is the default word to look up .
It extracts 5 information from the dictionary.
Speech of word
IPA Pronunciation
URL to dictionary
Definition
Audio Pronunciation
✅ Describe any prerequisites or dependencies that are required for this SmartBlock
API Key from Merriam Dictionary is required and the same can be obtained from https://dictionaryapi.com/register/index. There are multiple API Keys and this code works for "Learners Dictionary".
📷 Screenshot of your #42SmartBlock workflow/template from Roam
✂️ Copy of your #42SmartBlock from Roam
var url = "https://dictionaryapi.com/api/v3/references/learners/json/" + wordToLookUp + "/?key="+apiKey; var dicUrl = "https://learnersdictionary.com/definition/" + wordToLookUp var audio = "https://media.merriam-webster.com/audio/prons/en/us/mp3/" var responseText = $.ajax({url:url, type:"GET", async:false,}).responseText; var data = JSON.parse(responseText);
for(idx in data) { var shortDef = data[idx].meta["app-shortdef"] var ipa = "na" if (data[idx].hwi["prs"] != undefined){ var prs = data[idx].hwi["prs"] ipa = prs[0].ipa
} // Print the speech of word along with ipa pronunciation await roam42.smartBlocks.activeWorkflow.outputAdditionalBlock( shortDef["fl"] + " | / " + ipa + " / " );
// Print URL of Merriam Learner's dictionary await roam42.smartBlocks.activeWorkflow.outputAdditionalBlock(dicUrl);
// Definition of the word await roam42.smartBlocks.activeWorkflow.outputAdditionalBlock(shortDef["def"]);
// Embed audio for the word if (prs[0].sound != undefined){ await roam42.smartBlocks.activeWorkflow.outputAdditionalBlock(embed); }
// Fetch only the first record
break; } return '';``` %>
📋 Describe the SmartBlock
Look up English words from Merriam Learner's dictionary. Page title is the default word to look up . It extracts 5 information from the dictionary.
✅ Describe any prerequisites or dependencies that are required for this SmartBlock
API Key from Merriam Dictionary is required and the same can be obtained from https://dictionaryapi.com/register/index. There are multiple API Keys and this code works for "Learners Dictionary".
📷 Screenshot of your #42SmartBlock workflow/template from Roam
💡 Additional Info