相关疑难解决方法(0)

使用Python将云语音API的结果导出到JSON文件

我正在尝试通过 Google Speech API 将音频文件转换为印度语言的文本。API 返回类型为“google.cloud.speech_v1.types.SpeechRecognitionAlternative”的对象。我正在尝试将结果导出到 .json 文件。我对python很陌生。这是我在 python 中做的第一个项目。

    import io
    import os
    import pickle

    # Imports the Google Cloud client library
    from google.cloud
    import speech
    from google.cloud.speech
    import enums
    from google.cloud.speech
    import types

    client = speech.SpeechClient()

    audio = types.RecognitionAudio(uri = "gs://storage-staples-canada/client-data/TapTapTap.wav")
    config = types.RecognitionConfig(
      encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16,
      sample_rate_hertz = 16000,
      language_code = 'hi-IN',
      enable_word_time_offsets = True,
      speech_contexts = [speech.types.SpeechContext(phrases = ['?? ???? ???', '??? ??? ?????', '?? ??? ????? ???? ?????', '???? ??? ??? ????? ??? ??? ???? …
Run Code Online (Sandbox Code Playgroud)

python json dictionary google-speech-api

5
推荐指数
2
解决办法
2155
查看次数

Python:将API结果保存到json文件中?

这是我能够使用 python 3 通过 API 访问的数据的预览。

   [{'DBNOs': 2,
  'assists': 0,
  'boosts': 0,
  'damageDealt': 129.820038,
  'deathType': 'byplayer',
  'headshotKills': 0,
  'heals': 0,
  'killPlace': 35,
  'killPoints': 1295,
  'killPointsDelta': 3.15819788,
  'killStreaks': 0,
  'kills': 1,
  'lastKillPoints': 0,
  'lastWinPoints': 0,
  'longestKill': 3,
  'mostDamage': 0,
  'name': 'Esskedit',
  'playerId': 'account.7a54835609584b9c943b213345ea7ffb',
  'revives': 1,
  'rideDistance': 2023.24707,
  'roadKills': 0,
  'teamKills': 1,
  'timeSurvived': 655,
  'vehicleDestroys': 0,
  'walkDistance': 1113.72375,
  'weaponsAcquired': 0,
  'winPlace': 17,
  'winPoints': 1281,
  'winPointsDelta': -6.71400356}]
Run Code Online (Sandbox Code Playgroud)

我能够使用 json.dumps(variablename) 转储它并使其成为 json 对象,但如何将其保存为 json 文件?

谢谢

python api

5
推荐指数
1
解决办法
2万
查看次数

将字典保存为包含我可以不断添加的列的文件

我有货币的字典这里JSON.

为简单起见,我将提供一个示例:

{
    "AED": "united Arab Emirates Dirham",
    "AFN": "Afghan Afghani",
    ...
    "ZWL": "Zimbabwean Dollar"
}
Run Code Online (Sandbox Code Playgroud)

我希望将它们添加到一个文件中,我可以在不同的时间不断添加不同的货币组.该文件应具有货币代码名称的列(例如"AED")和名称的另一列.

我真的不知道从哪里开始.将非常感谢帮助指出我正确的方向.

我的字典代码如下:

import json
import urllib.request
def _fetch_currencies():
    f = urllib.request.urlopen(
        'http://openexchangerates.org/api/currencies.json')
    charset = f.info().get_param('charset', 'utf8')
    data = f.read()
    decoded = json.loads(data.decode(charset))
    print(json.dumps(decoded, indent=4))
Run Code Online (Sandbox Code Playgroud)

python dictionary currency file

2
推荐指数
1
解决办法
147
查看次数

如何将python字典保存到json文件中?

我有一本字典,例如:

a = {'a':1,'b':2,'c':3}
Run Code Online (Sandbox Code Playgroud)

我希望它保存在一个 json 文件中。

我如何使用原始的 python json 库来做到这一点?

请注意,我正在运行 Python 3.5.2,它有一个内置的 json 库。

python json dictionary

2
推荐指数
2
解决办法
1万
查看次数

将对象列表转换为 Json 数组

我是 python 的新手,我有一个这样的对象列表。

示例代码

>>> for val in las.version:
...     print(val.mnemonic)
...     print(val.unit)
...     print(val.value)
...     print(val.descr)
...
VERS

1.2
some description
WRAP

NO
another description
>>>
Run Code Online (Sandbox Code Playgroud)

我想将其转换为 JSON 数组。

{  
   "versionInformation":[  
      {  
         "mnemonic":"VERS",
         "unit":"",
         "value":"2.0",
         "description":"some description"
      },
      {  
         "mnemonic":"WRAP",
         "unit":"",
         "value":"NO",
         "description":"another description"
      }
   ]
}
Run Code Online (Sandbox Code Playgroud)

python json

2
推荐指数
1
解决办法
7351
查看次数

如何在 python 中将 JSON 写入具有空值的文件?

{“1”:空,“2”:假,“3”:真}

我不需要将它们转换为 None False True。

python

1
推荐指数
1
解决办法
1242
查看次数

使用 python 从 json 文件中删除引号

数据框“数据集”是由 PowerBI 自动生成的,这是我的结果dataset.head(10).to_clipboard(sep=',', index=False)

coordinates,status
"[143.4865219,-34.7560602]",not started
"[143.4865241,-34.7561332]",not started
"[143.4865264,-34.7562088]",not started
"[143.4865286,-34.7562818]",not started
"[143.4865305,-34.7563453]",not started
"[143.4865327,-34.7564183]",not started
"[143.486535,-34.756494]",not started
"[143.4865371,-34.756567]",not started
"[143.486539,-34.7566304]",not started
"[143.4865412,-34.7567034]",not started
Run Code Online (Sandbox Code Playgroud)

然后获取json

我这样做data=dataset.to_json(orient='records')

这给了我这个结果

[{"coordinates":"[143.4865219,-34.7560602]","status":"not started"},{"coordinates":"[143.4865241,-34.7561332]","status":"not started"},
Run Code Online (Sandbox Code Playgroud)

我如何得到这个,坐标值上没有引号

[{"coordinates":[143.4865219,-34.7560602],"status":"not started"},{"coordinates":[143.4865241,-34.7561332],"status":"not started"},
Run Code Online (Sandbox Code Playgroud)

编辑

 print(type(data))

<class 'str'>
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
2853
查看次数

标签 统计

python ×7

dictionary ×3

json ×3

api ×1

currency ×1

file ×1

google-speech-api ×1