英文:
How to read Simplified Mandarin Chinese characters From text file and save mp3 file using say command on Mac
问题
I am using Javascript. I have little experience with JavaScript and this is my first time trying to write a script. The Chinese text is not properly read in using this method. For example "他是一位非常著名的演员" gets saved as "‰ªñÊò؉∏ĉΩçÈùûÂ∏∏ËëóÂêçÁöÑʺîÂëò.aiff". I also know the pronunciation is not correct using this method. I've read this documentation and have searched around but can't find anything about this issue. I also have no idea how to write an mp3 file.
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var basePath = "path to directory";
var inputPath = basePath + "/input.txt";
var text = app.read(inputPath).split("\n");
for (let i = 0; i < text.length; i++) {
var recordingPath = basePath + "/" + text[i] + ".aiff";
app.say(text[i], {savingTo: recordingPath});
app.say(text[i]);
}
英文:
I am using Javascript. I have little experience with JavaScript and this is my first time trying to write a script. The Chinese text is not properly read in using this method. For example "他是一位非常著名的演员" gets saved as "‰ªñÊò؉∏ĉΩçÈùûÂ∏∏ËëóÂêçÁöÑʺîÂëò.aiff". I also know the pronunciation is not correct using this method. I've read this documentation and have searched around but can't find anything about this issue. I also have no idea how to write an mp3 file.
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var basePath = "path to directory";
var inputPath = basePath + "/input.txt";
var text = app.read(inputPath).split("\n");
for (let i = 0; i < text.length; i++) {
var recordingPath = basePath + "/" + text[i] + ".aiff";
app.say(text[i], {savingTo: recordingPath});
app.say(text[i]);
}
答案1
得分: 1
这似乎是一个编码问题。脚本不知道它试图读取什么,所以你必须告诉它以«class utf8»
编码。我不使用JavaScript,所以无法帮助你处理它的语法,但在AppleScript中,它会如下所示:
read file inputPath as «class utf8»
--> "他是一位非常著名的演员"
音频部分是独立的,即使你不知道如何录制为mp3,也有一些转换选项。iTunes可以将AIFF转换为mp3。我不确定Shell命令afconvert
是否可以转换为mp3(看起来不太可能),但它可以转换为m4a。
英文:
It looks like an encoding issue. The script doesn't know what it's trying to read so you have to tell it that it's encoded as «class utf8»
. I don't use javascript so I can't help you with its syntax but in applescript, it would look like this.
read file inputPath as «class utf8»
--> "他是一位非常著名的演员"
The audio stuff is separate but even if you don't know how to record to mp3, you have some conversion options. itunes can convert AIFF to mp3. I'm not sure whether the shell command afconvert
can convert to mp3 (doesn't look promising) but it can convert to m4a.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论