chatziko / ha-google-cloud-stt

Use Google Cloud Speech-to-Text in Home Assistant.
64 stars 13 forks source link

Unexpectedly high Google API costs #8

Open michaelblight opened 10 months ago

michaelblight commented 10 months ago

Google charged me $19 for speech-to-text on the 23rd-31st Dec for 609 minutes usage over 6200 requests. I didn't spend 10 hours talking, and nor did I use if that many times since I installed on the 28th. Do you have any thoughts on what might be happening? I have it hooked up to a Pi running satellite and 2 M5 atom echo devices. It looks like the bulk of the costs were for that first install day, but I can't find a graph that shows calls rather than latency, etc. It seems to have settled down since then, but is possibly charging me a few cents a day, whereas I would expect to be within the free quota.

I've not had to use Google's billing much before, so I'm trying to put in some limits, but they don't make it easy.

michaelblight commented 10 months ago

For some further context, I'm using my own local wakeword, so I assume that doesn't go to Google.

It's possible that was the day I was trying (and failing) to get the satellite working on the Pi in docker. It would hear the wakeword, play the awake sound and then do nothing. The last debug messages were "Streaming audio" and "Connected to snd service". Perhaps it was streaming the audio to Google without recognising the end of speech, so continuing to stream forever, and perhaps I left the container running for 10 hours (EDIT: Probably not, see edit in next comment)?

Here's a graph of the number of calls per hour on the 27-28th Dec. It looks like it's hitting a maximum of 60 calls per hour and then not doing any more. It's not clear to me how that gets to 6200 requests, but it about 10 hours.

image

Here is the chart of the last week for 30 minute intervals:

image

michaelblight commented 10 months ago

I'm trying to reproduce the problem, but it looks like the google graphs don't update very often. I went back to the non-docker version of the satellite, and noticed I'm getting a whole lot of stt-stream-failed errors - about one every 18 seconds. It successfully responded to my "what's the weather" request, so it's not clear to me why it's getting an stt-stream-failed error when nothing should be happening.

INFO:root:Waiting for wake word
DEBUG:root:Streaming audio
DEBUG:root:Event(type='transcript', data={'text': "what's the weather"}, payload=None)
INFO:root:Waiting for wake word
DEBUG:root:Streaming audio
DEBUG:root:Event(type='synthesize', data={'text': '19.1 ▒C and raining', 'voice': {'name': 'en_GB-alan-low'}}, payload=None)
DEBUG:root:Connected to snd service
Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
WARNING:root:Event(type='error', data={'text': 'speech-to-text failed', 'code': 'stt-stream-failed'}, payload=None)
WARNING:root:Event(type='error', data={'text': 'speech-to-text failed', 'code': 'stt-stream-failed'}, payload=None)
WARNING:root:Event(type='error', data={'text': 'speech-to-text failed', 'code': 'stt-stream-failed'}, payload=None)
WARNING:root:Event(type='error', data={'text': 'speech-to-text failed', 'code': 'stt-stream-failed'}, payload=None)
WARNING:root:Event(type='error', data={'text': 'speech-to-text failed', 'code': 'stt-stream-failed'}, payload=None)
WARNING:root:Event(type='error', data={'text': 'speech-to-text failed', 'code': 'stt-stream-failed'}, payload=None)
WARNING:root:Event(type='error', data={'text': 'speech-to-text failed', 'code': 'stt-stream-failed'}, payload=None)

EDIT: I think I know why the errors occur - I set a threshold of 10 per 30minutes so it doesn't get out of hand, and the graph shows 10 reached. So the question is why is it continually streaming to Google? It was hard to see on the graph because I was showing 30min intervals for the last 3 hours, but the data shows up in the next interval, which is in the future - so you have to show last 3 hours and then click ">" to see the future. If it helps, this is where it crashed out after I did a ctrl-C:

WARNING:root:Event(type='error', data={'text': 'speech-to-text failed', 'code': 'stt-stream-failed'}, payload=None)
WARNING:root:Event(type='error', data={'text': 'speech-to-text failed', 'code': 'stt-stream-failed'}, payload=None)
^CAborted by signal Interrupt...
Traceback (most recent call last):
  File "/data/wyoming-satellite/script/run", line 12, in <module>
    subprocess.check_call([context.env_exe, "-m", "wyoming_satellite"] + sys.argv[1:])
  File "/usr/lib/python3.11/subprocess.py", line 408, in check_call
    retcode = call(*popenargs, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 391, in call
    return p.wait(timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 1262, in wait
    return self._wait(timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 1997, in _wait
    (pid, sts) = self._try_wait(0)
                 ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 1955, in _try_wait
    (pid, sts) = os.waitpid(self.pid, wait_flags)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt
leranp commented 10 months ago

Same here with satellite connected. I stopped the service until everything will be clear :-(

chatziko commented 10 months ago

I never had this proble, but it looks like an issue with wyoming-satellite, not this extension. ha-google-cloud-stt just registers itself as an STT provider and performs a request to google only when HA asks it to. It should probably be reported to wyoming-satellite (which btw I still haven't tried, so far I'm still using homeassistant-satellite).

leranp commented 10 months ago

I never had this proble, but it looks like an issue with wyoming-satellite, not this extension. ha-google-cloud-stt just registers itself as an STT provider and performs a request to google only when HA asks it to. It should probably be reported to wyoming-satellite (which btw I still haven't tried, so far I'm still using homeassistant-satellite).

It is a satellite issue, i had this extension before the satellite and I didn't had this issue

llluis commented 10 months ago

It's possible that was the day I was trying (and failing) to get the satellite working on the Pi in docker. It would hear the wakeword, play the awake sound and then do nothing. The last debug messages were "Streaming audio" and "Connected to snd service". Perhaps it was streaming the audio to Google without recognising the end of speech, so continuing to stream forever, and perhaps I left the container running for 10 hours

Please see the issue on the satellite repo. If you are seeing the message 'Streaming audio' before the wake word, your local wake word detection may not be working properly.