MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/cpp-samples / main

Function main

speech/api/transcribe.cc:28–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26)""";
27
28int main(int argc, char** argv) try {
29 // [START speech_sync_recognize]
30 // [START speech_sync_recognize_gcs]
31 // Create a Speech client with the default configuration
32 auto client = speech::SpeechClient(speech::MakeSpeechConnection());
33 // Parse command line arguments.
34 auto const args = ParseArguments(argc, argv);
35 speech::v1::RecognizeRequest request;
36 *request.mutable_config() = args.config;
37 // [END speech_sync_recognize_gcs]
38 // [END speech_sync_recognize]
39 if (args.path.rfind("gs://", 0) == 0) {
40 // [START speech_sync_recognize_gcs]
41 // Pass the Google Cloud Storage URI to the request.
42 request.mutable_audio()->set_uri(args.path);
43 // [END speech_sync_recognize_gcs]
44 } else {
45 // [START speech_sync_recognize]
46 // Load the audio file from disk into the request.
47 auto content =
48 std::string{std::istreambuf_iterator<char>(
49 std::ifstream(args.path, std::ios::binary).rdbuf()),
50 {}};
51 request.mutable_audio()->mutable_content()->assign(std::move(content));
52 // [END speech_sync_recognize]
53 }
54 // [START speech_sync_recognize]
55 // [START speech_sync_recognize_gcs]
56 // Send audio content using Recognize().
57 auto response = client.Recognize(request);
58 if (!response) throw std::move(response).status();
59 // Dump the transcript of all the results.
60 for (auto const& result : response->results()) {
61 for (auto const& alternative : result.alternatives()) {
62 std::cout << alternative.confidence() << "\t" << alternative.transcript()
63 << "\n";
64 }
65 }
66 // [END speech_sync_recognize_gcs]
67 // [END speech_sync_recognize]
68 return 0;
69} catch (google::cloud::Status const& s) {
70 std::cerr << "Recognize failed with: " << s << "\n";
71 return 1;
72} catch (std::exception const& ex) {
73 std::cerr << "Standard C++ exception thrown: " << ex.what() << "\n"
74 << kUsage << "\n";
75 return 1;
76}

Callers

nothing calls this directly

Calls 1

ParseArgumentsFunction · 0.70

Tested by

no test coverage detected