teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

456

2019/09/06 12:12

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -4,7 +4,7 @@
4
4
  result_textをsample.pyでprintしたい
5
5
 
6
6
  #できないこと
7
- subprocessを使っている為「0」と表示されていまいます。
7
+ subprocessを使っている為 result_text = "ここの文字をsample.txtで出力したいです"ではなく「0」と表示されていまいます。
8
8
  コマンドを指定したうえでsample2.pyのresult_textの戻り値を取得するにはどのように設定すれば良いのでしょうか?
9
9
  ➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡の部分になります。
10
10
 

2

123

2019/09/06 12:12

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,9 +1,14 @@
1
1
  お世話になります。
2
2
  sample.pyとsample2.pyの間の変数戻り値について質問です。
3
+ #やりたいこと
4
+ result_textをsample.pyでprintしたい
5
+
6
+ #できないこと
3
- result_textをsample.pyでprintしたいのですがsubprocessを使っている為「0」と表示されていまいます。
7
+ subprocessを使っている為「0」と表示されていまいます。
4
8
  コマンドを指定したうえでsample2.pyのresult_textの戻り値を取得するにはどのように設定すれば良いのでしょうか?
5
9
  ➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡の部分になります。
6
10
 
11
+
7
12
  #sample.py
8
13
  ```
9
14
  from google.cloud import storage

1

追記

2019/09/06 12:11

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,10 +1,17 @@
1
1
  お世話になります。
2
2
  sample.pyとsample2.pyの間の変数戻り値について質問です。
3
3
  result_textをsample.pyでprintしたいのですがsubprocessを使っている為「0」と表示されていまいます。
4
- コマンドを指定しながらsample2.pyのresult_textの戻り値を取得するにはどのように設定すれば良いのでしょうか?
4
+ コマンドを指定したうえでsample2.pyのresult_textの戻り値を取得するにはどのように設定すれば良いのでしょうか?
5
+ ➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡の部分になります。
5
6
 
6
7
  #sample.py
7
8
  ```
9
+ from google.cloud import storage
10
+ from pydub import AudioSegment
11
+ import os
12
+ import subprocess
13
+ import sample2.py
14
+
8
15
  cmd = "python3 sample2.py gs://bucket/"
9
16
  result_text = subprocess.call(cmd.split())
10
17
  print(result_text)
@@ -13,9 +20,29 @@
13
20
  ```
14
21
  # !/usr/bin/env python
15
22
  # coding: utf-8
23
+
24
+ import argparse
25
+ import io
26
+ import os
27
+ import sys
28
+ import codecs
29
+ import datetime
30
+ import locale
16
- def sample2:
31
+ import subprocess
32
+ import shutil
33
+
34
+ def transcribe_gcs(gcs_uri):
17
- result_text = "ここの文字をsample.txtで出力したい"
35
+ result_text = "ここの文字をsample.txtで出力したいです" ➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡
36
+ return result_text➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡➡
37
+
38
+ if __name__ == '__main__':
39
+ parser = argparse.ArgumentParser(
18
- return result_text
40
+ description=__doc__,
41
+ formatter_class=argparse.RawDescriptionHelpFormatter)
42
+ parser.add_argument(
43
+ 'path', help='GCS path for audio file to be recognized')
44
+ args = parser.parse_args()
45
+ transcribe_gcs(args.path)
19
46
  ```
20
47
 
21
48
  宜しくお願いします。