samedi 21 septembre 2019

Trying to use a node module in the browser, is there a better way?

I am working on a text to speech application. I found a npm package called say. I would like the user be able to enter text in a text box and click the button to have the text be spoken to them. However I realized that you cannot run node in the browser, and you can't access DOM in Node.js. Is there a way to do accomplish this? Or is there a better method instead of using node for an application like this? Ps. Ive also thought about using a free text to speech rest API however I can't find any good ones. If you any recommendations please let me know

One other idea I have is to use Angular and node, however I cant find any documentation online that shows how to use a node package with Angular. I don't even know if this is possible.

Script.js
const say = require("say");
let button = document.querySelector("#button");

button.addEventListener("click", () =>{
    let text = document.querySelector("#input");
    alert(text);
    say.speak(text);
});

Server.js
let HTTP_PORT = process.env.HTTP_PORT || 8080;
let express = require("express");
let path = require("path");
let app = express();
app.use(express.static("public")); // JS and CSS files are considered static files.

app.get("/", (rew, res) =>{
  res.sendFile(path.join(__dirname, "index.html"));
});

app.listen(HTTP_PORT, () =>{
  console.log("The server has started!");
});




Aucun commentaire:

Enregistrer un commentaire