質問編集履歴
1
コード挿入のミスのため。
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,14 +9,18 @@
|
|
9
9
|
|
10
10
|
以下ソースコード
|
11
11
|
-------------------------------------------------------------------------------------------------------
|
12
|
+
```Python
|
13
|
+
import getpass
|
12
|
-
|
14
|
+
APIKEY = getpass.getpass()
|
13
15
|
|
16
|
+
#@title このセルを実行して record_audio を定義
|
17
|
+
|
14
|
-
#
|
18
|
+
# Install required libraries and packages
|
15
19
|
!pip install -qq pydub
|
16
20
|
!apt-get -qq update
|
17
21
|
!apt-get -qq install -y ffmpeg
|
18
22
|
|
19
|
-
#
|
23
|
+
# Define record_audio
|
20
24
|
import base64
|
21
25
|
import google.colab
|
22
26
|
import pydub
|
@@ -24,7 +28,7 @@
|
|
24
28
|
from io import BytesIO
|
25
29
|
|
26
30
|
def record_audio(file_id, framerate=16000, file_format='flac'):
|
27
|
-
#
|
31
|
+
# Record webm file from Colaboratory.
|
28
32
|
audio = google.colab._message.blocking_request(
|
29
33
|
'user_media',
|
30
34
|
{
|
@@ -34,15 +38,15 @@
|
|
34
38
|
},
|
35
39
|
timeout_sec=600)
|
36
40
|
|
37
|
-
#
|
41
|
+
# Convert web file into in_memory file.
|
38
42
|
mfile = BytesIO(base64.b64decode(audio[audio.index(',')+1:]))
|
39
43
|
|
40
|
-
#
|
44
|
+
# Store webm file locally.
|
41
45
|
with open('{0}.webm'.format(file_id), 'wb') as f:
|
42
46
|
mfile.seek(0)
|
43
47
|
f.write(mfile.read())
|
44
48
|
|
45
|
-
#
|
49
|
+
# Open stored web file and save it as wav with sample_rate=16000
|
46
50
|
output_file = '{0}.{1}'.format(file_id, file_format)
|
47
51
|
_ = pydub.AudioSegment.from_file('{0}.webm'.format(file_id), codec='opus')
|
48
52
|
_.set_frame_rate(16000).export(output_file, format=file_format)
|
@@ -52,9 +56,10 @@
|
|
52
56
|
|
53
57
|
record_audio('ja-sample')
|
54
58
|
audio_filename='ja-sample.flac'
|
55
|
-
|
59
|
+
```
|
56
|
-
エラー
|
60
|
+
エラー
|
57
61
|
---------------------------------------------------------------------------
|
62
|
+
```ここに言語を入力
|
58
63
|
AttributeError Traceback (most recent call last)
|
59
64
|
<ipython-input-3-2e60a39e1187> in <module>()
|
60
65
|
----> 1 record_audio('ja-sample')
|
@@ -69,6 +74,7 @@
|
|
69
74
|
|
70
75
|
AttributeError: 'dict' object has no attribute 'index'
|
71
76
|
|
77
|
+
```
|
72
78
|
--------------------------------------------------------------------------------------------------------
|
73
79
|
以下Google ColaboratoryのノートブックURLです。
|
74
80
|
https://colab.research.google.com/github/GoogleCloudPlatform/gcp-getting-started-lab-jp/blob/master/machine_learning/cloud_ai_building_blocks/speech-to-speech/speech_to_speech.ipynb#scrollTo=2OWkkepTWSbG
|