I have been trying to run the following code from this link.
import io
import os
# Imports the Google Cloud client library
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
# Instantiates a client
client = speech.SpeechClient()
# 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)
config = types.RecognitionConfig(
encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=16000,
language_code='en-US')
# Detects speech in the audio file
response = client.recognize(config, audio)
for result in response.results:
print('Transcript: {}'.format(result.alternatives[0].transcript))
However, I am getting the following error when I run it using python 3.4.2 on a raspberry pi.
Traceback (most recent call last):
File "script.py", line 10, in <module>
client = speech.SpeechClient()
File "/usr/local/lib/python3.4/dist- packages/google/cloud/speech_v1/gapic/speech_client.py", line 137, in __init__
credentials=credentials,
File "/usr/local/lib/python3.4/dist-packages/google/cloud/speech_v1/gapic/transports/speech_grpc_transport.py", line 76, in __init__
channel)
File "/usr/local/lib/python3.4/dist- packages/google/api_core/operations_v1/operations_client.py", line 59, in __init__
self.operations_stub = operations_pb2.OperationsStub(channel)
AttributeError: 'module' object has no attribute 'OperationsStub'
I have been trying to get over this for about 3 days now and I have not found any solution.
Any help would be appreciated.
Not sure if you still have the problem. I went through the same thing this morning.
I, apparently, seemed to have a version of googleapis-common-protos installed which was built without GRPC support (1.6.0b6). I downgraded it to 1.5.3, restarted jupyter server and its working perfectly fine now. Please refer to this link.
Google Cloud Github
Related
I'm just trying to create a simple speech to text transcriber using the openai whisper module and streamlit for web application but having some problems.
It is giving me error
Traceback (most recent call last):
File "C:\Users\Satyam Singh\AppData\Local\Programs\Python\Python310\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 565, in _run_script
exec(code, module.__dict__)
File "C:\Users\Satyam Singh\Desktop\Python Project\app.py", line 19, in <module>
transcription = model.transcribe(audio_file)
File "C:\Users\Satyam Singh\AppData\Local\Programs\Python\Python310\lib\site-packages\whisper\transcribe.py", line 84, in transcribe
mel = log_mel_spectrogram(audio)
File "C:\Users\Satyam Singh\AppData\Local\Programs\Python\Python310\lib\site-packages\whisper\audio.py", line 112, in log_mel_spectrogram audio = torch.from_numpy(audio)
**TypeError: expected np.ndarray (got NoneType)**
Here's my code
import streamlit as st
import whisper
from audio_recorder_streamlit import audio_recorder
# App Title Name
st.title("Speech to Text")
# uploading an audio file
# audio_file = st.file_uploader("Upload Audio", type=["wav","mp3","m4a"])
audio_file = audio_recorder()
if audio_file:
st.audio(audio_file, format="audio/wav")
model = whisper.load_model("base")
st.text("Whisper Model Loaded")
transcription = model.transcribe(audio_file)
print(transcription['text'])
if st.sidebar.button("Transcribe Audio"):
if audio_file is not None:
st.sidebar.success("Transcribing Audio")
transcription = model.transcribe(audio_file.name)
st.sidebar.success("Transcription Complete")
st.text(transcription["text"])
else:
st.sidebar.error("Please Upload an Audio File")
I want something like Baseten
I want this code to work or something more innovative which works same way like this one or Baseten.
I'm using the below code to connect to the Google BigQuery API. It only works intermittently. After this part, I attempt to send a dataframe to a BQ table via the "to_gbq" function. That part also only sometimes works, and other times fails due to the same error message.
Code:
from google.cloud import bigquery
from google.oauth2 import service_account
path_to_json = 'gbq_key.json'
my_credentials = service_account.Credentials.from_service_account_file(path_to_json)
my_project = 'myprojectnameishere'
client = bigquery.Client(credentials=my_credentials, project=my_project)
print('connected')
AttributeError: module 'google.api_core' has no attribute 'client_options'
Detailed error:
File "/home/my_user_name/get_mini_bq_helper.py", line 8, in <module>
client = bigquery.Client(credentials=my_credentials, project=my_project)
File "/home/my_user_name/.local/lib/python3.10/site-packages/google/cloud/bigquery/client.py", line 226, in __init__
super(Client, self).__init__(
File "/home/my_user_name/.local/lib/python3.10/site-packages/google/cloud/client/__init__.py", line 321, in __init__
Client.__init__(
File "/home/my_user_name/.local/lib/python3.10/site-packages/google/cloud/client/__init__.py", line 157, in __init__
client_options = google.api_core.client_options.ClientOptions()
AttributeError: module 'google.api_core' has no attribute 'client_options'
I am hosting this on PythonAnywhere but I randomly get this error locally as well. Sometimes it connects with no issue, but most of the time I get this error. Also, I couldn't find this error anywhere on Google/Stack Overflow. Any ideas what it might be?
I have been trying to read a thermocouple temperature on my raspberrypi however cant get the raspi to communicate with the adafruit MAX 31856. I have downloaded necessary libraries and checked that all connections are secure and correct however keep running into this error when I try to execute this code.
Any help is greatly appreciated!!
CODE
import board
import digitalio
import adafruit_max31856
spi = board.SPI()
cs = digitalio.DigitalInOut(board.D5)
cs.direction = digitalio.Direction.OTUPUT
thermocouple = adafruit_max31856.MAX31856(spi,cs)
print(thermocouple.temperature)
ERROR:
Traceback (most recent call last):
File "/home/pi/test4.py", line 6, in <module>
spi = board.SPI()
File "/usr/local/lib/python3.7/dist-packages/board.py", line 299, in SPI
return busio.SPI(SCLK, MOSI, MISO)
File "/usr/local/lib/python3.7/dist-packages/busio.py", line 289, in __init__
self._spi = _SPI(portId)
File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/spi.py", line 25, in __init__
self._spi = spi.SPI(device=(portid, 0))
File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/spi.py", line 167, in __init__
raise IOError("{} does not exist".format(device))
OSError: /dev/spidev0.0 does not exist
Code
Errors
Most probably there is a device driver loaded for spi0-0 and that removes /dev/spidev0.0 device.
check your /boot/config.txt for overlays loading MAX 31856 driver module.
if you want to use adafruit_max31856 lib you shouldn't be loading this driver. hope that helps
I'm starting on a project using Clarifai. However, when I define the app, I'm getting a key error:
from clarifai.rest import ClarifaiApp
from clarifai.rest import Image as ClImage
import os
from glob import glob
api_key = 'my api key'
app = ClarifaiApp(api_key=api_key) # Error occurs here
model_id = 'model id'
concepts = ['concept1', 'concept2', 'concept3']
Traceback (most recent call last):
File "C:\Users\crayo\uShoe\main.py", line 6, in <module>
app = ClarifaiApp(api_key=api_key)
File "C:\Users\user\project\venv\lib\site-packages\clarifai\rest\client.py", line 124, in __init__
self.models = Models(self.api, self.solutions) # type: Models
File "C:\Users\user\project\venv\lib\site-packages\clarifai\rest\client.py", line 1068, in __init__
self.model_id_cache = self.init_model_cache()
File "C:\Users\user\project\venv\lib\site-packages\clarifai\rest\client.py", line 1088, in init_model_cache
model_type = m.output_info['type']
KeyError: 'type'
I'm not sure what's causing this error, so if someone could provide input I'd appreciate it! Thanks!
You are using the deprecated Python REST package: https://github.com/Clarifai/clarifai-python. Please replace your code with the new & updated Python gRPC client: https://github.com/Clarifai/clarifai-python-grpc
Make sure to uninstall the REST package to avoid conflicts.
You can find our API docs & code snippets here: https://docs.clarifai.com
'str' object has no attribute 'long_running_recognize'. This error is occurring at the last line of the code shown. I jump into the code and see no obvious reason for it to fail. Jumps out at the wrap_method below.
if "long_running_recognize" not in self._inner_api_calls:
self._inner_api_calls[
"long_running_recognize"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.long_running_recognize,
default_retry=self._method_configs["LongRunningRecognize"].retry,
default_timeout=self._method_configs["LongRunningRecognize"].timeout,
client_info=self._client_info,
)
The only issue that I could conceive here is maybe the audio file is too large(45mb...53 min). But the code break happens in a location that doesn't appear to relate to this.
import io
import os
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
with open("path\\My First Project-edb18653fedf.json") as f:
GOOGLE_APPLICATION_CREDENTIALS = f.read()
client = speech.SpeechClient(GOOGLE_APPLICATION_CREDENTIALS)
file_path = "audio\\102.flac"
with io.open(file_path, 'rb') as audio_file:
content = audio_file.read()
audio = types.RecognitionAudio(content=content)
config = types.RecognitionConfig(
encoding=enums.RecognitionConfig.AudioEncoding.FLAC,
sample_rate_hertz=32000,
language_code='en-US')
operation = client.long_running_recognize(config, audio)
Connected to pydev debugger (build 191.7479.30)
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\helpers\pydev\pydevd.py", line 1758, in <module>
main()
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\helpers\pydev\pydevd.py", line 1752, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\helpers\pydev\pydevd.py", line 1147, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/shear/Documents/PythonScripts/GStTEnv/SpeechToText/CloudSpeechText.py", line 105, in <module>
operation = client.long_running_recognize(config, audio)
File "C:\Users\shear\GStTEnv\lib\site-packages\google\cloud\speech_v1\gapic\speech_client.py", line 314, in long_running_recognize
self.transport.long_running_recognize,
AttributeError: 'str' object has no attribute 'long_running_recognize'
Did you try to prove out your theory about the length of the audio? What happens if you trim the audio and try it?
Does it happen if you try a curl request at the command line instead of code?
I’d like to see if I can help. To diagnose further, would you be able to provide:
- Exact steps to reproduce
- Pointer to github repo if available
- As much of the code as you can provide
- Exact error messages
- Language Code (config)
- All configuration options applicable
- Sample audio file with all personal data removed (on Google Drive or Cloud Storage)