这是我要从url读取音频文件的代码。这段代码给我一个错误。
import speech_recognition as sr
r = sr.Recognizer()
audio = sr.AudioFile('http://www.wavsource.com/snds_2018-06-03_5106726768923853/people/comedians/carlin_logic.wav')
with audio as source:
audio = r.record(source)
错误:
IOError: [Errno 22] invalid mode ('rb') or filename: 'http://www.wavsource.com/snds_2018-06-03_5106726768923853/people/comedians/carlin_logic.wav'
我还有另一段代码,我也想在这里从url读取音频文件方面获得帮助。
from watson_developer_cloud import SpeechToTextV1
file = 'http://www.wavsource.com/snds_2018-06-03_5106726768923853/people/comedians/carlin_logic.wav'
with open(file,
'rb') as audio_file:
data = speech_to_text.recognize(
audio=audio_file,
countinuous = True,
content_type='audio/wav',
interim_results = True,
smart_formatting = True,
timestamps=True,
speaker_labels = True)
错误:
IOError: [Errno 22] invalid mode ('rb') or filename: 'http://www.wavsource.com/snds_2018-06-03_5106726768923853/people/comedians/carlin_logic.wav'