我正在尝试使用NodeJs Text To Speech Client Libary
以电子方式运行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>
任何帮助将不胜感激
答案 0 :(得分:0)
“ path”参数必须为字符串类型。收到的类型对象 在validateString(internal / validators.js:112:11) 在Object.basename(path.js:671:5)
这很简单:您没有传递有效的路径(字符串类型)。
<script src="./scripts/speech/ttscli.js"></script>
您没有提到您的项目结构-renderer
上下文相对于上面的路径在哪里?在页面脚本中执行console.log(__dirname)
,以查看页面路径并将其与上面的路径进行比较。