Вот мой код -
Код: Выделить всё
app = Flask(__name__)
client = TranscribeStreamingClient(region=)
async def write_chunks(stream,data):
# This connects the raw audio chunks generator coming from the microphone
# and passes them along to the transcription stream.
async for chunk in data:
await stream.input_stream.send_audio_event(audio_chunk=chunk)
await stream.input_stream.end_stream()
class MyEventHandler(TranscriptResultStreamHandler):
def handle_transcript_event(self, transcript_event: TranscriptEvent):
# This handler can be implemented to handle transcriptions as needed.
results = transcript_event.transcript.results
for result in results:
for alt in result.alternatives:
print(alt.transcript)
async def handle_client(data):
print("Received audio")
stream = await client.start_stream_transcription(
language_code="en-US",
media_sample_rate_hz=24000,
media_encoding="pcm"
)
handler = MyEventHandler(stream.output_stream)
# This connects the raw audio chunks generator coming from the microphone
# and passes them along to the transcription stream.
await asyncio.gather(write_chunks(stream,data), handler.handle_events())
async def main():
server = await websockets.serve(handle_client, "localhost", 8282)
await server.wait_closed()
asyncio.run(main())
Код: Выделить всё
Received audio
connection handler failed
Traceback (most recent call last):
File "\AppData\Roaming\Python\Python312\site-packages\websockets\legacy\server.py", line 245, in handler
await self.ws_handler(self)
File "realtime_amazon_py.py", line 46, in handle_client
await asyncio.gather(write_chunks(stream,data), handler.handle_events())
File "\AppData\Roaming\Python\Python312\site-packages\amazon_transcribe\handlers.py", line 28, in handle_events
await self.handle_transcript_event(event)
TypeError: object NoneType can't be used in 'await' expression
Подробнее здесь: https://stackoverflow.com/questions/790 ... used-in-aw