node.js - Electron : “path”参数必须为字符串类型。收到的类型对象

标签 node.js electron google-text-to-speech

我正在尝试使用NodeJs Text To Speech Client Libary以 Electron 方式运行Google Text-To-Speech

我可以在项目(在其中创建浏览器窗口的位置)的require('@google-cloud/text-to-speech');中使用main.js,但不能在页面内的脚本中运行它。

我得到的错误如下:

Uncaught TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object
    at validateString (internal/validators.js:112:11)
    at Object.basename (path.js:671:5)
    at GrpcClient.loadProto (path\to\project\node_modules\google-gax\build\src\grpc.js:117:29)
    at new TextToSpeechClient (path\to\project\node_modules\@google-cloud\text-to-speech\build\src\v1\text_to_speech_client.js:106:32)
    at file://path/to/project/scripts/speech/ttscli.js:7:16

来自位于scripts/speech/ttscli.js中的这个code
nodeIntegration设置为true,并且scripts/speech/ttscli.js的用法如下:
<script src="./scripts/speech/ttscli.js"></script>

任何帮助将不胜感激

最佳答案

The "path" argument must be of type string. Received type object at validateString (internal/validators.js:112:11) at Object.basename (path.js:671:5)



这很简单:您没有传递有效的路径(字符串类型)。
<script src="./scripts/speech/ttscli.js"></script>

您没有提到您的项目结构-相对于上面的路径,您的renderer上下文在哪里?在页面脚本中执行console.log(__dirname)以查看页面路径并将其与上面的路径进行比较。

关于node.js - Electron : “path”参数必须为字符串类型。收到的类型对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60589155/

相关文章:

android - 避免打开 TTS 引擎选择弹出窗口

audio - 如何使用 Google TTS 从文本创建 mp3?

electron - Electron 中的图标

javascript - 有没有办法从 Mongoose 模式中获取所有唯一的数组值?

node.js - Azure:当队列中有消息时如何触发nodejs webjob?

node.js - 使用 ObjectId 键和字符串数组定义映射作为 mongoose 模式中的值

javascript - Electron v1.7 : Close, 最大化和最大化

javascript - 我应该如何在不向用户显示的情况下使用 Electron 呈现网页?

android - 有没有办法将 Google TTS 用作外部库?

mysql - Express View 引擎无法识别发送到前端的数据