I want to use recognize_google to analyze the number in the wav file
try:
temp = r.recognize_google(".//splitAudio//split.wav",language="zh-TW")
print("You have said \n" + temp )
print("Audio Recorded Successfully \n ")
except Exception as e:
print("Error : " + str(e))
but I got the following error: Error : audio_data must be audio data
I have found this answer for a while, but I don't figure out.
Who can help me,i really appreciate it,thanks.
I do not have time to install stuff and find a WAV file but here's what The Ultimate Guide To Speech Recognition With Python says re "Using record() to Capture Data From a File"
import speech_recognition as sr
r = sr.Recognizer()
harvard = sr.AudioFile('harvard.wav')
with harvard as source:
audio = r.record(source)
r.recognize_google(audio)
Related
I'm having trouble with this code, i have all the needed requirements downloaded, butt it hust gives me a blinking pointer.
import speech_recognition as sr
r=sr.Recognizer()
print(sr.Microphone.list_microphone_names())
with sr.Microphone() as source:
# r.energy_threshold()
print("say anything : ")
r.adjust_for_ambient_noise(source,duration=2)
audio= r.listen(source)
try:
text = r.recognize_google(audio)
print(text)
except:
print("sorry, could not recognise")
In the following code, I have an issue with speech recognition. The audio WAV file duration is 4 seconds only, however I can only got the transcript for only the last two seconds.
import speech_recognition as sr
audio_data = sr.AudioFile('f1.wav')
recognizer = sr.Recognizer()
with audio_data as file_audio:
print("Start Transcribing File ...")
recognizer.adjust_for_ambient_noise(file_audio)
file_audio = recognizer.record(file_audio)
print(recognizer.recognize_google(file_audio))
Any idea how to fix that or how to convert the audio file to WAV to specific setttings that allows me to get the whole transcript?
I tried to use the following code to recognize a 5 min audio
import speech_recognition as sr
from os import path
from pydub import AudioSegment
import wavio
from scipy.io import wavfile
test_file = open("test.txt", "w+")
sound = AudioSegment.from_mp3("001.mp3")
sound.export("001.wav", format="wav")
AUDIO_FILE = "001.wav"
r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
audio = r.listen(source)
try:
text = r.recognize_google(audio)
print(text)
test_file.write(text+". ")
except:
print('Run again')
But it only return the very first couple words: "listening diagnostic pretest page 143", do you guys know why it didn't recognize the whole audio?
How can I convert sound from website to a text? When I click the button in a website is play a sound but my problem is how can I convert it to a text without using microphone just the website and the 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...')
Here is my code but I don't have a wav file just the voice coming from the website what I trying to convert.
Example of what I trying to make
when I click the button in the website it plays hello and the python will get the sound from the website and print it.
Try downloading the file first, I don't know the location or format of your audio file so this is a guess:
EDIT: added a url to a real audio file and it works, it fails with poor quality audio though
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)
Output
Converting audio transcripts into text ...
this is a huge confidence boost
speech to text in python using audio file.
This is answer for this question.
You have install pyaudio and SpeechRecognition.
and audio file format should be in WAV file.
Its code for speech to text (input from audio file).
import speech_recognition as sr
r = sr.Recognizer()
audio = 'trial.wav'
with sr.AudioFile(audio) as source:
audio = r.record(source)
print ('Done!')
try:
text = r.recognize_google(audio)
print (text)
except Exception as e:
print (e)
If you want different languages to be converted. You can use below code.
import speech_recognition as sr
r = sr.Recognizer()
with sr.AudioFile('Audio.wav') as source:
audio = r.listen(source)
try:
text = (r.recognize_google(audio, language="IN_HI"))
print('working on...')
print(text)
except:
print('Sorry.. run again..')