{"id":3869,"date":"2023-04-25T13:57:42","date_gmt":"2023-04-25T04:57:42","guid":{"rendered":"https:\/\/appinventor.tmsoftwareinc.com\/?p=3869"},"modified":"2023-04-27T04:34:23","modified_gmt":"2023-04-26T19:34:23","slug":"iphone%e7%89%88%e8%a9%b1%e3%81%97%e3%81%a6%ef%bc%81%e3%81%9d%e3%81%ae%ef%bc%91","status":"publish","type":"post","link":"https:\/\/appinventor.tmsoftwareinc.com\/en\/archives\/3869","title":{"rendered":"Talk To Me (Part 1) for iPhone"},"content":{"rendered":"<p><span><span class=\"\">We have developed iPhone apps using Google&#8217;s Bard and OpenAI&#8217;s GPT-4 that function similarly to the &#8220;Talk To Me (Part 1)&#8221; App Inventor app. Bard needed more steps. Xcode12.2 on macOS 10.15.7 is used. <a href=\"#GPT-4\">GPT-4 section is here<\/a>. Keep in mind that large language models, such as Google&#8217;s Bard and OpenAI&#8217;s GPT-4, do not return the same results when given the same prompt.&#8221;<\/span><\/span><\/p>\n<h2 id=\"bard\">Bard<\/h2>\n<h4>Prompt<\/h4>\n<blockquote>\n<div class=\"group w-full text-gray-800 dark:text-gray-100 border-b border-black\/10 dark:border-gray-900\/50 dark:bg-gray-800\">\n<div class=\"text-base gap-4 md:gap-6 md:max-w-2xl lg:max-w-xl xl:max-w-3xl p-4 md:py-6 flex lg:px-0 m-auto\">\n<div class=\"relative flex w-[calc(100%-50px)] flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]\">\n<div class=\"flex flex-grow flex-col gap-3\">\n<div class=\"min-h-[20px] flex flex-col items-start gap-4 whitespace-pre-wrap\">\n<p class=\"p1\">Do you know App Inventor App called Talk To Me (part 1)?<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/blockquote>\n<h4>Answer<\/h4>\n<blockquote><p>Yes, I am familiar with the App Inventor App called Talk To Me (part 1). It is a tutorial that teaches you how to create a simple text-to-speech app using the MIT App Inventor platform. The tutorial is divided into two parts: part 1 teaches you how to create a button that speaks when it is clicked, and part 2 teaches you how to make the app respond to shaking and let a user put in a phrase for the phone to speak out loud.<\/p>\n<p>To create a Talk To Me app, you will need to have the MIT App Inventor software installed on your computer. Once you have installed the software, you can open it and create a new project. In the project designer, you will need to add a button and a text-to-speech component to your app. You can then connect the button to the text-to-speech component so that when the button is clicked, the text-to-speech component will speak the text that is displayed on the button.<\/p>\n<p>Once you have created your app, you can test it by clicking the &#8220;Run&#8221; button in the MIT App Inventor software. The app will be installed on your phone, and you can then test it by clicking the button on your phone.<\/p>\n<p>The Talk To Me app is a great way to learn how to use the MIT App Inventor platform. It is a simple app that is easy to create, but it can be used to learn some of the basic concepts of app development. If you are interested in learning more about app development, I encourage you to check out the MIT App Inventor website<\/p><\/blockquote>\n<h4>Prompt<\/h4>\n<blockquote>\n<p class=\"query-text ng-star-inserted\">Create an iPhone App which works like App Inventor App called TalkToMe (part 1) using Xcode 12.2 and SwiftUI. I don\u2019t want to use storyboard.<\/p>\n<\/blockquote>\n<h4>Answer<\/h4>\n<blockquote><p>Sure, here are the steps on how to create an iPhone App which works like App Inventor App called TalkToMe (part 1) using Xcode 12.2 and SwiftUI without using storyboard:<\/p>\n<ol>\n<li>Open Xcode 12.2 and create a new project.<\/li>\n<li>Select the &#8220;Single View App&#8221; template and click &#8220;Next&#8221;.<\/li>\n<li>Enter a name for your project and click &#8220;Next&#8221;.<\/li>\n<li>Select a location for your project and click &#8220;Create&#8221;.<\/li>\n<li>In the project navigator, select the &#8220;ContentView.swift&#8221; file.<\/li>\n<li>Delete the code in the file and replace it with the following code:<\/li>\n<\/ol>\n<p><code-block _nghost-ng-c3642145518=\"\" ng-version=\"0.0.0-PLACEHOLDER\"><\/code-block><\/p>\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block ng-star-inserted\">\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block-wrapper header gmat-subhead-2\">Code snippet<\/div>\n<pre _ngcontent-ng-c3642145518=\"\"><code _ngcontent-ng-c3642145518=\"\">import SwiftUI\r\n\r\nstruct ContentView: View {\r\n    @State var text = \"\"\r\n    \r\n    var body: some View {\r\n        TextField(\"Enter text\", text: $text)\r\n            .padding()\r\n            .onSubmit {\r\n                \/\/ Speak the text that was entered.\r\n                let synthesizer = AVSpeechSynthesizer()\r\n                synthesizer.speak(text)\r\n            }\r\n    }\r\n}\r\n<\/code><\/pre>\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block-wrapper footer gmat-overline\">\n<div _ngcontent-ng-c3642145518=\"\">Use code with caution. <a _ngcontent-ng-c3642145518=\"\" href=\"https:\/\/bard.google.com\/faq#coding\" target=\"_blank\" rel=\"noopener noreferrer\" aria-label=\"Learn more (opens in a new window)\" class=\"disclaimer-suffix\">Learn more<\/a><\/div>\n<\/div>\n<\/div>\n<p><code-block _nghost-ng-c3642145518=\"\" ng-version=\"0.0.0-PLACEHOLDER\"><\/code-block><\/p>\n<ol start=\"7\">\n<li>Click the &#8220;Play&#8221; button in the top left corner of the Xcode window to run your app.<\/li>\n<li>Enter some text in the text field and press Enter. The text will be spoken aloud by your phone.<\/li>\n<\/ol>\n<p>You can now use your app to speak any text that you enter.<\/p><\/blockquote>\n<h4>Prompt<\/h4>\n<blockquote>\n<p class=\"query-text ng-star-inserted\">Remove textfield and always speech \u201cCongratulations! You&#8217;ve made your first app.\u201d when Speak button is clicked. Give me the whole code again.<\/p>\n<\/blockquote>\n<h4>Answer<\/h4>\n<blockquote><p>Sure, here is the code for the app with the text field removed and the text &#8220;Congratulations! You&#8217;ve made your first app.&#8221; always spoken when the &#8220;Speak&#8221; button is clicked:<\/p>\n<p><span style=\"font-size: 1.4rem; font-family: Meiryo, -apple-system, BlinkMacSystemFont, '.SFNSDisplay-Regular', 'Hiragino Kaku Gothic Pro', 'Yu Gothic', 'MS PGothic', 'Segoe UI', Verdana, Helvetica, Arial, sans-serif;\"><code-block _nghost-ng-c3642145518=\"\" ng-version=\"0.0.0-PLACEHOLDER\"><\/code-block><\/span><\/p>\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block ng-star-inserted\">\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block-wrapper header gmat-subhead-2\">Code snippet<\/div>\n<pre _ngcontent-ng-c3642145518=\"\"><code _ngcontent-ng-c3642145518=\"\">import SwiftUI\r\n\r\nstruct ContentView: View {\r\n    \r\n    var body: some View {\r\n        Button(action: {\r\n            \/\/ Speak the text.\r\n            let synthesizer = AVSpeechSynthesizer()\r\n            synthesizer.speak(\"Congratulations! You've made your first app.\")\r\n        }) {\r\n            Text(\"Speak\")\r\n        }\r\n    }\r\n}\r\n<\/code><\/pre>\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block-wrapper footer gmat-overline\">\n<div _ngcontent-ng-c3642145518=\"\">Use code with caution. <a _ngcontent-ng-c3642145518=\"\" href=\"https:\/\/bard.google.com\/faq#coding\" target=\"_blank\" rel=\"noopener noreferrer\" aria-label=\"Learn more (opens in a new window)\" class=\"disclaimer-suffix\">Learn more<\/a><\/div>\n<\/div>\n<\/div>\n<p><code-block _nghost-ng-c3642145518=\"\" ng-version=\"0.0.0-PLACEHOLDER\"><\/code-block><\/p>\n<p>This code creates a simple button that, when clicked, speaks the text &#8220;Congratulations! You&#8217;ve made your first app.&#8221; You can now use your app to speak this text whenever you want.<\/p><\/blockquote>\n<h4>Prompt<\/h4>\n<blockquote>\n<p class=\"query-text ng-star-inserted\">I got an error &#8220;Cannot find &#8216;AVSpeechSynthesizer&#8217; in scope&#8221;<\/p>\n<\/blockquote>\n<h4>Answer<\/h4>\n<blockquote><p>I apologize for the error. The AVSpeechSynthesizer class is part of the AVFoundation framework, which is not imported by default in SwiftUI. To fix the error, you need to import the AVFoundation framework at the top of your code:<\/p>\n<p><code-block _nghost-ng-c3642145518=\"\" ng-version=\"0.0.0-PLACEHOLDER\"><\/code-block><\/p>\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block ng-star-inserted\">\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block-wrapper header gmat-subhead-2\">Code snippet<\/div>\n<pre _ngcontent-ng-c3642145518=\"\"><code _ngcontent-ng-c3642145518=\"\">import AVFoundation\r\n<\/code><\/pre>\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block-wrapper footer gmat-overline\">\n<div _ngcontent-ng-c3642145518=\"\">Use code with caution. <a _ngcontent-ng-c3642145518=\"\" href=\"https:\/\/bard.google.com\/faq#coding\" target=\"_blank\" rel=\"noopener noreferrer\" aria-label=\"Learn more (opens in a new window)\" class=\"disclaimer-suffix\">Learn more<\/a><\/div>\n<\/div>\n<\/div>\n<p><code-block _nghost-ng-c3642145518=\"\" ng-version=\"0.0.0-PLACEHOLDER\"><\/code-block><\/p>\n<p>Once you have imported the AVFoundation framework, the error should go away. You can then try running your app again.<\/p><\/blockquote>\n<h4>Prompt<\/h4>\n<div _ngcontent-ng-c59595912=\"\" class=\"query-content\" id=\"user-query-content-4\">\n<blockquote>\n<p class=\"query-text ng-star-inserted\">I got an error &#8220;Cannot convert value of type &#8216;String&#8217; to expected argument type &#8216;AVSpeechUtterance'&#8221;<\/p>\n<\/blockquote>\n<\/div>\n<h4>Answer<\/h4>\n<blockquote><p>I apologize for the error. The AVSpeechSynthesizer class expects an AVSpeechUtterance object as its argument, not a simple string. To fix the error, you need to create an AVSpeechUtterance object and pass it to the AVSpeechSynthesizer class:<\/p>\n<p><code-block _nghost-ng-c3642145518=\"\" ng-version=\"0.0.0-PLACEHOLDER\"><\/code-block><\/p>\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block ng-star-inserted\">\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block-wrapper header gmat-subhead-2\">Code snippet<\/div>\n<pre _ngcontent-ng-c3642145518=\"\"><code _ngcontent-ng-c3642145518=\"\">let utterance = AVSpeechUtterance(string: \"Congratulations! You've made your first app.\")\r\n\r\nlet synthesizer = AVSpeechSynthesizer()\r\nsynthesizer.speak(utterance)\r\n<\/code><\/pre>\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block-wrapper footer gmat-overline\">\n<div _ngcontent-ng-c3642145518=\"\">Use code with caution. <a _ngcontent-ng-c3642145518=\"\" href=\"https:\/\/bard.google.com\/faq#coding\" target=\"_blank\" rel=\"noopener noreferrer\" aria-label=\"Learn more (opens in a new window)\" class=\"disclaimer-suffix\">Learn more<\/a><\/div>\n<\/div>\n<\/div>\n<p><code-block _nghost-ng-c3642145518=\"\" ng-version=\"0.0.0-PLACEHOLDER\"><\/code-block><\/p>\n<p>Once you have made this change, the error should go away. You can then try running your app again.<\/p><\/blockquote>\n<h4>Prompt<\/h4>\n<blockquote>\n<p class=\"query-text ng-star-inserted\">Give me the whole code<\/p>\n<\/blockquote>\n<h4>Answer<\/h4>\n<blockquote><p>Sure, here is the whole code:<\/p>\n<p>import SwiftUI import AVFoundation<\/p>\n<p>struct ContentView: View {<\/p>\n<p><code-block _nghost-ng-c3642145518=\"\" ng-version=\"0.0.0-PLACEHOLDER\"><\/code-block><\/p>\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block ng-star-inserted\">\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block-wrapper header gmat-subhead-2\">Code snippet<\/div>\n<pre _ngcontent-ng-c3642145518=\"\"><code _ngcontent-ng-c3642145518=\"\">var body: some View {\r\n    Button(action: {\r\n        \/\/ Speak the text.\r\n        let utterance = AVSpeechUtterance(string: \"Congratulations! You've made your first app.\")\r\n        let synthesizer = AVSpeechSynthesizer()\r\n        synthesizer.speak(utterance)\r\n    }) {\r\n        Text(\"Speak\")\r\n    }\r\n}\r\n<\/code><\/pre>\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block-wrapper footer gmat-overline\">\n<div _ngcontent-ng-c3642145518=\"\">Use code with caution. <a _ngcontent-ng-c3642145518=\"\" href=\"https:\/\/bard.google.com\/faq#coding\" target=\"_blank\" rel=\"noopener noreferrer\" aria-label=\"Learn more (opens in a new window)\" class=\"disclaimer-suffix\">Learn more<\/a><\/div>\n<\/div>\n<\/div>\n<p><code-block _nghost-ng-c3642145518=\"\" ng-version=\"0.0.0-PLACEHOLDER\"><\/code-block><\/p>\n<p>}<\/p>\n<p>This code creates a simple button that, when clicked, speaks the text &#8220;Congratulations! You&#8217;ve made your first app.&#8221; You can now use your app to speak this text whenever you want.<\/p><\/blockquote>\n<h2>Creating iPhone App with Xcode<\/h2>\n<h3>Create a Xcode project<\/h3>\n<p>Launch Xcode and create an iOS App project named TalkToMe-Bard, with Interface as SwiftUI and Language as Swift.<\/p>\n<h3 id=\"swift\">Paste swift code<\/h3>\n<p>Paste the swift code created by Bard into ContentView.swift. The code is<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>import SwiftUI\r\n\r\nimport AVFoundation\r\n\r\nstruct ContentView: View {\r\n\r\nvar body: some View {\r\n\r\n\u00a0 \u00a0 Button(action: {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \/\/ Speak the text.\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 let utterance = AVSpeechUtterance(string: \"Congratulations! You've made your first app.\")\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 let synthesizer = AVSpeechSynthesizer()\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 synthesizer.speak(utterance)\r\n\r\n\u00a0 \u00a0 }) {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 Text(\"Speak\")\r\n\r\n\u00a0 \u00a0 }\r\n\r\n}\r\n\r\n}<\/code><\/pre>\n<\/div>\n<h3>Run<\/h3>\n<p>The execution result is as shown here. It will talk when &#8220;Speak&#8221; button is clicked. You can watch the demo video by clicking the mage below.<\/p>\n<p><a href=\"https:\/\/youtube.com\/shorts\/BOx7DS2FTMg\" rel=\"attachment noopener wp-att-3883\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-Bard-529x1024.png\" alt=\"\" width=\"529\" height=\"1024\" class=\"alignnone wp-image-3883 size-large\" srcset=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-Bard-529x1024.png 529w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-Bard-155x300.png 155w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-Bard-768x1487.png 768w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-Bard-793x1536.png 793w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-Bard-274x530.png 274w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-Bard-292x565.png 292w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-Bard-367x710.png 367w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-Bard-374x725.png 374w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-Bard.png 1032w\" sizes=\"(max-width: 529px) 100vw, 529px\" \/><\/a><\/p>\n<h2 id=\"GPT-4\">GPT-4<\/h2>\n<h4>Prompt<\/h4>\n<blockquote>\n<div class=\"group w-full text-gray-800 dark:text-gray-100 border-b border-black\/10 dark:border-gray-900\/50 dark:bg-gray-800\">\n<div class=\"text-base gap-4 md:gap-6 md:max-w-2xl lg:max-w-xl xl:max-w-3xl p-4 md:py-6 flex lg:px-0 m-auto\">\n<div class=\"relative flex w-[calc(100%-50px)] flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]\">\n<div class=\"flex flex-grow flex-col gap-3\">\n<div class=\"min-h-[20px] flex flex-col items-start gap-4 whitespace-pre-wrap\">\n<p class=\"p1\">Do you know App Inventor App called Talk To Me (part 1)?<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/blockquote>\n<h4>Answer<\/h4>\n<blockquote><p>Yes, I am familiar with the App Inventor App called Talk To Me (part 1). It is a tutorial that teaches you how to create a simple text-to-speech app using the MIT App Inventor platform. The tutorial is divided into two parts: part 1 teaches you how to create a button that speaks when it is clicked, and part 2 teaches you how to make the app respond to shaking and let a user put in a phrase for the phone to speak out loud.<\/p>\n<p>To create a Talk To Me app, you will need to have the MIT App Inventor software installed on your computer. Once you have installed the software, you can open it and create a new project. In the project designer, you will need to add a button and a text-to-speech component to your app. You can then connect the button to the text-to-speech component so that when the button is clicked, the text-to-speech component will speak the text that is displayed on the button.<\/p>\n<p>Once you have created your app, you can test it by clicking the &#8220;Run&#8221; button in the MIT App Inventor software. The app will be installed on your phone, and you can then test it by clicking the button on your phone.<\/p>\n<p>The Talk To Me app is a great way to learn how to use the MIT App Inventor platform. It is a simple app that is easy to create, but it can be used to learn some of the basic concepts of app development. If you are interested in learning more about app development, I encourage you to check out the MIT App Inventor website<\/p><\/blockquote>\n<h4>Prompt<\/h4>\n<blockquote>\n<p class=\"query-text ng-star-inserted\">Create an iPhone App which works like App Inventor App called TalkToMe (part 1) using Xcode 12.2 and SwiftUI. I don\u2019t want to use storyboard.<\/p>\n<\/blockquote>\n<h4>Answer<\/h4>\n<blockquote>\n<p class=\"p1\">Creating an iPhone app similar to the TalkToMe app using Xcode 12.2 and SwiftUI without using a storyboard is a great project idea. I will guide you through the steps to create a simple version of the app.<\/p>\n<ol class=\"ol1\">\n<li class=\"li1\">Launch Xcode and create a new project.\n<ul class=\"ul1\">\n<li class=\"li1\"><span class=\"s1\"><\/span>Select &#8220;App&#8221; as the template and click &#8220;Next&#8221;.<\/li>\n<li class=\"li1\"><span class=\"s1\"><\/span>Give your project a name, for example, &#8220;TalkToMeSwiftUI&#8221;.<\/li>\n<li class=\"li1\"><span class=\"s1\"><\/span>Make sure the &#8220;Interface&#8221; option is set to &#8220;SwiftUI&#8221; and &#8220;Lifecycle&#8221; is set to &#8220;SwiftUI App&#8221;.<\/li>\n<li class=\"li1\"><span class=\"s1\"><\/span>Set the &#8220;Language&#8221; to &#8220;Swift&#8221;, and choose a location to save your project. Click &#8220;Create&#8221;.<\/li>\n<\/ul>\n<\/li>\n<li class=\"li1\">Remove the default ContentView.swift file.\n<ul class=\"ul1\">\n<li class=\"li1\"><span class=\"s1\"><\/span>In the project navigator, right-click on &#8220;ContentView.swift&#8221; and select &#8220;Delete&#8221;. Move the file to trash.<\/li>\n<\/ul>\n<\/li>\n<li class=\"li1\">Create a new SwiftUI file for your main view.\n<ul class=\"ul1\">\n<li class=\"li1\"><span class=\"s1\"><\/span>In the project navigator, right-click on your app folder and select &#8220;New File&#8221;.<\/li>\n<li class=\"li1\"><span class=\"s1\"><\/span>Choose &#8220;SwiftUI View&#8221; and click &#8220;Next&#8221;.<\/li>\n<li class=\"li1\"><span class=\"s1\"><\/span>Name the file &#8220;TalkToMeView&#8221; and click &#8220;Create&#8221;.<\/li>\n<\/ul>\n<\/li>\n<li class=\"li1\">Edit the TalkToMeView.swift file to create the user interface:<\/li>\n<\/ol>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>import SwiftUI\r\n\r\nimport AVFoundation\r\n\r\nstruct TalkToMeView: View {\r\n\r\n\u00a0 \u00a0 @State private var inputText: String = \"\"\r\n\r\n\u00a0\u00a0 \u00a0\r\n\r\n\u00a0 \u00a0 var body: some View {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 VStack {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 TextField(\"Type something...\", text: $inputText)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .padding()\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .textFieldStyle(RoundedBorderTextFieldStyle())\r\n\r\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Button(action: {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 speak(text: inputText)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }) {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Text(\"Speak\")\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .font(.title)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .bold()\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .padding()\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .background(Color.blue)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .foregroundColor(.white)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .cornerRadius(10)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 .padding()\r\n\r\n\u00a0 \u00a0 }\r\n\r\n\u00a0\u00a0 \u00a0\r\n\r\n\u00a0 \u00a0 func speak(text: String) {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 let utterance = AVSpeechUtterance(string: text)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 utterance.voice = AVSpeechSynthesisVoice(language: \"en-US\")\r\n\r\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 let synthesizer = AVSpeechSynthesizer()\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 synthesizer.speak(utterance)\r\n\r\n\u00a0 \u00a0 }\r\n\r\n}<\/code><\/pre>\n<\/div>\n<p class=\"p2\"><span style=\"font-size: 1.4rem; font-family: Meiryo, -apple-system, BlinkMacSystemFont, '.SFNSDisplay-Regular', 'Hiragino Kaku Gothic Pro', 'Yu Gothic', 'MS PGothic', 'Segoe UI', Verdana, Helvetica, Arial, sans-serif;\">This code sets up a simple user interface with a TextField for user input and a Button to trigger the speech synthesis. The speak(text:) function uses the AVFoundation framework to convert the input text to speech.<\/span><\/p>\n<ol class=\"ol1\">\n<li class=\"li1\">Update the main app file (YourApp.swift):<\/li>\n<\/ol>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>import SwiftUI\r\n\r\n@main\r\n\r\nstruct TalkToMeSwiftUIApp: App {\r\n\r\n\u00a0 \u00a0 var body: some Scene {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 WindowGroup {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 TalkToMeView()\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 }\r\n\r\n}<\/code><\/pre>\n<\/div>\n<p class=\"p1\">This will set the main view of the app to the TalkToMeView.<\/p>\n<ol class=\"ol1\">\n<li class=\"li1\">Run the app on an iOS simulator or a physical device.<\/li>\n<\/ol>\n<p class=\"p1\">Now you have a basic version of the TalkToMe app using SwiftUI without using a storyboard. You can further customize the UI or add additional features as needed.<\/p>\n<div _ngcontent-ng-c3642145518=\"\" class=\"code-block ng-star-inserted\">\n<pre _ngcontent-ng-c3642145518=\"\"><code _ngcontent-ng-c3642145518=\"\"><\/code><\/pre>\n<\/div>\n<\/blockquote>\n<h4>Prompt<\/h4>\n<blockquote>\n<p class=\"p1\">Remove textfield and always speech \u201cCongratulations! You&#8217;ve made your first app.\u201d.Give me whole code again.<\/p>\n<\/blockquote>\n<h4>Answer<\/h4>\n<blockquote>\n<p class=\"p1\">Sure, I&#8217;ve modified the code to remove the TextField and always speak &#8220;Congratulations! You&#8217;ve made your first app.&#8221; Here&#8217;s the updated code:<\/p>\n<ol class=\"ol1\">\n<li class=\"li1\">TalkToMeView.swift:<\/li>\n<\/ol>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>import SwiftUI\r\n\r\nimport AVFoundation\r\n\r\nstruct TalkToMeView: View {\r\n\r\n\u00a0 \u00a0 var body: some View {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 VStack {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Button(action: {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 speak(text: \"Congratulations! You've made your first app.\")\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }) {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Text(\"Speak\")\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .font(.title)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .bold()\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .padding()\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .background(Color.blue)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .foregroundColor(.white)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .cornerRadius(10)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 .padding()\r\n\r\n\u00a0 \u00a0 }\r\n\r\n\u00a0\u00a0 \u00a0\r\n\r\n\u00a0 \u00a0 func speak(text: String) {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 let utterance = AVSpeechUtterance(string: text)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 utterance.voice = AVSpeechSynthesisVoice(language: \"en-US\")\r\n\r\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 let synthesizer = AVSpeechSynthesizer()\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 synthesizer.speak(utterance)\r\n\r\n\u00a0 \u00a0 }\r\n\r\n}<\/code><\/pre>\n<\/div>\n<ol class=\"ol1\">\n<li class=\"li1\">YourApp.swift (replace &#8220;YourApp&#8221; with the actual name of your app):<\/li>\n<\/ol>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>import SwiftUI\r\n\r\n@main\r\n\r\nstruct YourApp: App {\r\n\r\n\u00a0 \u00a0 var body: some Scene {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 WindowGroup {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 TalkToMeView()\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 }\r\n\r\n}<\/code><\/pre>\n<\/div>\n<p class=\"p1\">Now when you run the app, there will be no TextField, and the app will always speak &#8220;Congratulations! You&#8217;ve made your first app.&#8221; when you tap the &#8220;Speak&#8221; button.<\/p>\n<\/blockquote>\n<h2>Creating iPhone App with Xcode<\/h2>\n<h3>Create a Xcode project<\/h3>\n<p>Launch Xcode and create an iOS App project named TalkToMe-GPT, with Interface as SwiftUI and Language as Swift.<\/p>\n<h3 id=\"swift\">Paste swift code<\/h3>\n<p>Paste the swift code created by GPT-4 into TalkToMe-GPTApp.swift. The code is<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>import SwiftUI\r\n\r\n@main\r\n\r\nstruct TalkToMe_GPTApp: App {\r\n\r\n\u00a0 \u00a0 var body: some Scene {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 WindowGroup {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 TalkToMeView()\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 }\r\n\r\n}<\/code><\/pre>\n<\/div>\n<p>Create TalkToMeView.swift file and paste the swift code created by GPT-4. The code is<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>import SwiftUI\r\n\r\nimport AVFoundation\r\n\r\nstruct TalkToMeView: View {\r\n\r\n\u00a0 \u00a0 var body: some View {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 VStack {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Button(action: {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 speak(text: \"Congratulations! You've made your first app.\")\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }) {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Text(\"Speak\")\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .font(.title)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .bold()\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .padding()\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .background(Color.blue)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .foregroundColor(.white)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .cornerRadius(10)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 .padding()\r\n\r\n\u00a0 \u00a0 }\r\n\r\n\u00a0\u00a0 \u00a0\r\n\r\n\u00a0 \u00a0 func speak(text: String) {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 let utterance = AVSpeechUtterance(string: text)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 utterance.voice = AVSpeechSynthesisVoice(language: \"en-US\")\r\n\r\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 let synthesizer = AVSpeechSynthesizer()\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 synthesizer.speak(utterance)\r\n\r\n\u00a0 \u00a0 }\r\n\r\n}<\/code><\/pre>\n<\/div>\n<h3>Run<\/h3>\n<p>The execution result is as shown here. It will talk when &#8220;Speak&#8221; button is clicked. You can watch the demo video by clicking the mage below.<\/p>\n<p><a href=\"https:\/\/youtube.com\/shorts\/Q0eWtGY_S9g\" rel=\"attachment noopener wp-att-3900\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-GPT-529x1024.png\" alt=\"\" width=\"529\" height=\"1024\" class=\"alignnone wp-image-3900 size-large\" srcset=\"https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-GPT-529x1024.png 529w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-GPT-155x300.png 155w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-GPT-768x1487.png 768w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-GPT-793x1536.png 793w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-GPT-274x530.png 274w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-GPT-292x565.png 292w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-GPT-367x710.png 367w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-GPT-374x725.png 374w, https:\/\/appinventor.tmsoftwareinc.com\/wp-content\/uploads\/2023\/04\/TalkToMe-GPT.png 1032w\" sizes=\"(max-width: 529px) 100vw, 529px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have developed iPhone apps using Google&#8217;s Bard and OpenAI&#8217;s GPT-4 that function similarly to the &#8220;Talk To Me (Part 1)&#8221; App Inventor app. Bard needed more steps. Xcode12.2 on macOS 10.15.7 is used. GPT-4 section is here. Keep in mind that large language models, such as Google&#8217;s Bard and OpenAI&#8217;s GPT-4, do not return [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":"","_locale":"en_US","_original_post":"https:\/\/appinventor.tmsoftwareinc.com\/?p=3835"},"categories":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/posts\/3869"}],"collection":[{"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/comments?post=3869"}],"version-history":[{"count":32,"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/posts\/3869\/revisions"}],"predecessor-version":[{"id":3910,"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/posts\/3869\/revisions\/3910"}],"wp:attachment":[{"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/media?parent=3869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/categories?post=3869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appinventor.tmsoftwareinc.com\/wp-json\/wp\/v2\/tags?post=3869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}