Closed mirceapasoi closed 8 months ago
Taking a look at this.
The @dataclass
was an experiment that I forgot about and unintentionally commited, but the older input should still work just like before.
This should still work:
# Copyright 2023 Deepgram SDK contributors. All Rights Reserved.
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
# SPDX-License-Identifier: MIT
import os
from dotenv import load_dotenv
import logging, verboselogs
from datetime import datetime, timedelta
from io import BufferedReader
from deepgram import DeepgramClientOptions
import logging
from deepgram import (
DeepgramClient,
DeepgramClientOptions,
StreamSource,
AnalyzeOptions,
TextSource,
)
load_dotenv()
TEXT_FILE = "conversation.txt"
def main():
try:
# STEP 1 Create a Deepgram client using the API key in the environment variables
config = DeepgramClientOptions(
verbose=logging.SPAM,
)
deepgram = DeepgramClient("", config)
# OR use defaults
# deepgram = DeepgramClient()
# STEP 2 Call the transcribe_file method on the prerecorded class
stream = open(TEXT_FILE, "rb")
payload: StreamSource = {
"stream": stream,
}
options = AnalyzeOptions(
language="en",
intents=True,
)
response = deepgram.read.analyze.v("1").analyze_text(payload, options)
print(response.to_json(indent=4))
except Exception as e:
print(f"Exception: {e}")
if __name__ == "__main__":
main()
If the dataclass thing doesn't panout, I will revert the name back to ReadStreamSource
and convert back to the TypedDict
. Will have this done tomorrow.
@mirceapasoi I tested the above code with 3.1.6, it should work just fine.
@dvonthenen I am using transcribe_file
, which seems to crash around here, due to the "key" in provided_source
check calling __getitem__
:
if is_buffer_source(source):
body = source["buffer"]
elif is_readstream_source(source):
body = source["stream"]
...
def is_buffer_source(provided_source: PrerecordedSource) -> bool:
return "buffer" in provided_source
def is_readstream_source(provided_source: PrerecordedSource) -> bool:
return "stream" in provided_source
I reverted it.... GitHub is dying this morning. Waiting for the outage-ish to end so I can post a new release. Closing since the update has been merged.
What is the current behavior?
StreamSource
(previously calledReadStreamSource
) doesn't seem to work properly.Steps to reproduce
Expected behavior
It should work to instantiate
StreamSource
with anio.BufferedReader
(and it does in older versions of the SDK).Please tell us about your environment
Other information
I believe this is the change that broke it: https://github.com/deepgram/deepgram-python-sdk/commit/450211ee6618309382bde5c7a9982bb1f77aecac#diff-33563c4bf51563ef7c839d34ac0037cf2cff20456e65bcead1fda7f002696435