回答編集履歴
2
コード修正
answer
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
|
14
14
|
const request = {
|
15
15
|
input: {text: text},
|
16
|
-
voice: {languageCode: '
|
16
|
+
voice: {languageCode: 'ja-JP', ssmlGender: 'FEMALE'},
|
17
17
|
audioConfig: {audioEncoding: 'MP3'},
|
18
18
|
};
|
19
19
|
const [response] = await client.synthesizeSpeech(request);
|
1
コードを追加
answer
CHANGED
@@ -2,7 +2,25 @@
|
|
2
2
|
|
3
3
|
base64で音声データが帰ってきますので`mp3`ファイルにデコードすれば出来上がりです。
|
4
4
|
|
5
|
+
```js
|
5
|
-
|
6
|
+
const textToSpeech = require('@google-cloud/text-to-speech');
|
7
|
+
const fs = require('fs');
|
8
|
+
const util = require('util');
|
9
|
+
|
10
|
+
const client = new textToSpeech.TextToSpeechClient();
|
11
|
+
const text = 'こんにちは';
|
12
|
+
const outputFile = 'output.mp3';
|
13
|
+
|
14
|
+
const request = {
|
15
|
+
input: {text: text},
|
16
|
+
voice: {languageCode: 'en-US', ssmlGender: 'FEMALE'},
|
17
|
+
audioConfig: {audioEncoding: 'MP3'},
|
18
|
+
};
|
19
|
+
const [response] = await client.synthesizeSpeech(request);
|
20
|
+
const writeFile = util.promisify(fs.writeFile);
|
21
|
+
await writeFile(outputFile, response.audioContent, 'binary');
|
22
|
+
console.log(`Audio content written to file: ${outputFile}`);
|
23
|
+
```
|
24
|
+
|
6
25
|
- [Cloud Text-to-Speech の基本 | Cloud Text-to-Speech のドキュメント](https://cloud.google.com/text-to-speech/docs/basics?hl=ja)
|
7
|
-
- [音声ファイルの作成 | Cloud Text-to-Speech のドキュメント](https://cloud.google.com/text-to-speech/docs/create-audio?hl=ja)
|
26
|
+
- [音声ファイルの作成 | Cloud Text-to-Speech のドキュメント](https://cloud.google.com/text-to-speech/docs/create-audio?hl=ja)
|
8
|
-
- [Base64 でエンコードされたコンテンツのデコード | Cloud Text-to-Speech のドキュメント](https://cloud.google.com/text-to-speech/docs/base64-decoding?hl=ja)
|