简体   繁体   中英

Bad: FileNotFoundError: [Errno 2] No such file or directory

I use ubuntu and python to run google cloud speech. First I put all the code in a file called lu.py :

 import io
 import os
 from google.cloud import speech
...

# The name of the audio file to transcribe
file_name = os.path.join(
    os.path.dirname(__file__),
    'resources',
    'audio.raw')

# Loads the audio into memory
with io.open(file_name, 'rb') as audio_file:
    content = audio_file.read()
    audio = types.RecognitionAudio(content=content)
...

When I ran python lu.py in terminal, it said

FileNotFoundError: [Errno 2] No such file or directory: 'resources/audio.raw'

I'm not familiar with the path problem, so I don't know where is wrong.

means file that contains the name audio.raw was not found in the path resources/[filename]

You can set the path name in the block below this comment:

# The name of the audio file to transcribe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM