【问题标题】:Convert sound from website to text in python在python中将声音从网站转换为文本
【发布时间】:2020-05-14 10:30:25
【问题描述】:

如何将声音从网站转换为文本?当我单击网站中的按钮时播放声音,但我的问题是如何在不使用麦克风的情况下将其转换为文本,而仅使用网站和 python。

import speech_recognition as sr

r = sr.Recognizer()
with sr.AudioFile('my.wav') as source:

    audio_text = r.listen(source)

    try:
        text = r.recognize_google(audio_text)
        print('Converting audio transcripts into text ...')
        print(text)

    except:
         print('Sorry.. run again...')

这是我的代码,但我没有 wav 文件,只有来自网站的声音,我试图转换。

我尝试制作的示例

当我点击网站上的按钮时,它会播放 hello,python 将从网站获取声音并打印出来。

【问题讨论】:

  • 您有音频剪辑的示例链接吗?

标签: python


【解决方案1】:

先尝试下载文件,我不知道你的音频文件的位置或格式,所以这是一个猜测:

编辑:向真实的音频文件添加了一个 url,它可以工作,但它会因音频质量差而失败

import requests
import speech_recognition as sr

def download(url, path):
    response = requests.get(url)     # get the response of the url
    with open(path, 'wb') as file:   # create the file
        file.write(response.content) # write response contents to the file

def transcribe(path):
    r = sr.Recognizer()
    with sr.AudioFile(path) as source:
        audio_text = r.record(source)

        text = r.recognize_google(audio_text)
        print('Converting audio transcripts into text ...')
        return text


audio_url = 'https://google.github.io/tacotron/publications/parrotron/audio/norm_vctk/03_norm_input.wav'
audio_path = './speech.wav'

download(audio_url, audio_path)

audio_text = transcribe(audio_path)

print(audio_text)

输出

Converting audio transcripts into text ...
this is a huge confidence boost

【讨论】:

  • 但该网站不使用音频文件或 wav 或 mp3。它使用 javascript 来读取文本以发出声音
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-22
  • 1970-01-01
  • 2012-11-25
  • 1970-01-01
  • 2018-12-19
  • 2020-03-12
  • 2013-03-09
相关资源
最近更新 更多