|
| 1 | +# Copyright 2022 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import os |
| 16 | +import uuid |
| 17 | + |
| 18 | +import pytest |
| 19 | + |
| 20 | +import conversation_management |
| 21 | +import conversation_profile_management |
| 22 | +import participant_management |
| 23 | + |
| 24 | + |
| 25 | +PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") |
| 26 | +AUDIO_FILE_PATH = "{0}/resources/book_a_room.wav".format( |
| 27 | + os.path.realpath(os.path.dirname(__file__)), |
| 28 | +) |
| 29 | + |
| 30 | + |
| 31 | +@pytest.fixture |
| 32 | +def conversation_profile_display_name(): |
| 33 | + return f"sample_conversation_profile_{uuid.uuid4()}" |
| 34 | + |
| 35 | + |
| 36 | +@pytest.fixture |
| 37 | +def conversation_profile_id(conversation_profile_display_name): |
| 38 | + # Create conversation profile. |
| 39 | + response = conversation_profile_management.create_conversation_profile_article_faq( |
| 40 | + project_id=PROJECT_ID, |
| 41 | + display_name=conversation_profile_display_name |
| 42 | + ) |
| 43 | + conversation_profile_id = response.name.split("conversationProfiles/")[1].rstrip() |
| 44 | + |
| 45 | + yield conversation_profile_id |
| 46 | + |
| 47 | + # Delete the conversation profile. |
| 48 | + conversation_profile_management.delete_conversation_profile( |
| 49 | + PROJECT_ID, conversation_profile_id |
| 50 | + ) |
| 51 | + |
| 52 | + |
| 53 | +@pytest.fixture |
| 54 | +def conversation_id(conversation_profile_id): |
| 55 | + # Create conversation. |
| 56 | + response = conversation_management.create_conversation( |
| 57 | + project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id |
| 58 | + ) |
| 59 | + conversation_id = response.name.split("conversations/")[1].rstrip() |
| 60 | + |
| 61 | + yield conversation_id |
| 62 | + |
| 63 | + # Complete the conversation. |
| 64 | + conversation_management.complete_conversation(project_id=PROJECT_ID, conversation_id=conversation_id) |
| 65 | + |
| 66 | + |
| 67 | +@pytest.fixture |
| 68 | +def participant_id(conversation_id): |
| 69 | + response = participant_management.create_participant( |
| 70 | + project_id=PROJECT_ID, conversation_id=conversation_id, role="END_USER" |
| 71 | + ) |
| 72 | + participant_id = response.name.split("participants/")[1].rstrip() |
| 73 | + yield participant_id |
| 74 | + |
| 75 | + |
| 76 | +# Test live transcription with streaming_analyze_content. |
| 77 | +def test_analyze_content_audio_stream(capsys, conversation_id, participant_id): |
| 78 | + # Call StreamingAnalyzeContent to transcribe the audio. |
| 79 | + participant_management.analyze_content_audio_stream( |
| 80 | + project_id=PROJECT_ID, |
| 81 | + conversation_id=conversation_id, |
| 82 | + participant_id=participant_id , |
| 83 | + audio_file_path=AUDIO_FILE_PATH, |
| 84 | + ) |
| 85 | + out, _ = capsys.readouterr() |
| 86 | + assert "book a room" in out |
0 commit comments