Jekyll2022-04-22T15:02:57-05:00https://blog.carlresearch.org/feed.xmlCARL BlogThe official blog of CARL ResearchAdd cross-referencing in your Research Papers and Pdfs created with MS Word2020-11-12T00:00:00-06:002020-11-12T00:00:00-06:00https://blog.carlresearch.org/research%20tips/research/paper%20formatting/2020/11/12/Add-cross-referencing-in-your-paper-pdfs-created-with-MS-Word<p>If you’re here, you’ve in all probability written the first draft of your paper and made a pdf for submission to your favorite journal/conference or open-access repository. Congratulations, pat yourself on the back, the hard part is now behind you. In a series of blog posts, <strong>I’m going to tell you how you can make your articles easier to read and understand and thus get more cited</strong>!</p>
<h2 id="okay-so-why-do-we-need-in-text-cross-referencing">Okay! So why do we need in-text cross-referencing?</h2>
<p>In-text cross referencing is useful whenever you want to make it easier for the reader to reach any position in the document like</p>
<ul>
<li><strong>Citations</strong> to you references in the bibliography section</li>
<li><strong>Sections</strong> and sub-sections</li>
<li><strong>Tables</strong> and <strong>Figures</strong></li>
<li>Sometimes, page numbers (discouraged as it’s easy to overlook relevant page numbers that change at a later stage)</li>
<li>Any other position you wish to jump to</li>
</ul>
<p>Whenever we write a paper, we are spreading knowledge and it’s the duty of a good writer to make the journey as easy, fun and fulfilling for the reader as possible. A big way of doing this will be cross-referencing.</p>
<p>Word’s internal cross-referencing feature seems to be quite arcane and complicated to use if you’re using some reference manager like Mendeley or Zotero. In this day and age if you’re writing papers, you’re undoubtedly using some reference manager. I couldn’t find any easy way to get this internal cross-referencing to work. <em>Hence I designed a hackish way to get this done in just a few simple steps.</em></p>
<h2 id="careful-">Careful !?</h2>
<p>You cannot easily modify these links after creation, and modifying the citations with Mendeley or Zotero later will NOT update the cross-referencing, thus completely messing up your document. Hence please make sure you’re doing this as the absolute last stage of typesetting.</p>
<p>Also keep a saved copy, just on the off-chance, you really need to modify the reference list later.</p>
<h2 id="great-tell-me-how-to-do-it">Great! Tell me how to do it!</h2>
<p>In this section, we’ll see how we can do cross-referencing for citations in a few simple steps</p>
<ol>
<li>
<p>If you’re using any reference manager like Mendeley or Zotero, you’d have something called field-codes in your text. You can check it by pressing <code class="highlighter-rouge">Alt+F9</code>. If you see some weird text appearing, those are field codes and it’s recommended to remove them. Select your entire text by pressing <code class="highlighter-rouge">Ctrl+A</code> and then get rid of them by pressing <code class="highlighter-rouge">Ctrl+Shift+F9</code></p>
</li>
<li>
<p>To make it easier to see all in-text citations within square-brackets, it’s ideal to highlight all of them and there’s an automated way to do this as well as described <a href="https://cybertext.wordpress.com/2011/06/20/word-replace-and-reformat-text-inside-square-brackets-using-wildcards/">here with explanation</a>. In the off-chance the link disappears, I’d reproduce those steps here:</p>
<p>a. Select all text with Ctrl+A.</p>
<p>b. Press <code class="highlighter-rouge">Ctrl+H</code> to open the Find and Replace dialog box.</p>
<p>c. Click the <code class="highlighter-rouge">More</code> button.</p>
<p>d. Select the <code class="highlighter-rouge">Use wildcards</code> check box an select <code class="highlighter-rouge">All</code> in the Search dropdown.</p>
<p>e. Put your cursor into the <code class="highlighter-rouge">Find what</code> field.</p>
<p>f. Type the following exactly (or copy it from here): <code class="highlighter-rouge">(\[)(*)(\])</code></p>
<p>g. Make sure the highlight option is NOT No color.</p>
<p>h. Click the <code class="highlighter-rouge">Format</code> button, and select Highlight.</p>
<p>i. Click on <code class="highlighter-rouge">Replace All</code>.</p>
<p>If your citations use parenthesis, instead of square-brackets, use <code class="highlighter-rouge">\((*)\)</code> in Step f. Why this works can be found <a href="https://bioexpressblog.wordpress.com/2014/04/16/highlight-words-enclosed-in-parenthesis-in-ms-word/">here</a>. This should select anything within parenthesis including non-citations like <code class="highlighter-rouge">(D)</code>, please ignore those. This does work for compound references like <code class="highlighter-rouge">(Author1 1993; Author2 and Author3 2017)</code>. Word has a bug where if a search fails, consequent searches might also fail, in that case, the best way is to restart the word processor saving the existing changes.</p>
<p><img src="/images/2020-11-12-Add-cross-referencing-in-your-paper-pdfs-created-with-MS-Word/Highlight.png" alt="Highlight" title="Here's how we highlight all our citations." /></p>
<p>Verify it all looks as expected and proceed.</p>
</li>
<li>
<p>In your Bibliography/References section, click on the first reference, on the part <code class="highlighter-rouge">[1]</code>, in between the brackets and press <code class="highlighter-rouge">Ctrl+Shift+F5</code> to insert a bookmark.</p>
</li>
<li>
<p>Name the reference <code class="highlighter-rouge">r01</code>(to later maintain order for upto 99 references easily) and press <code class="highlighter-rouge">Enter</code>.</p>
</li>
<li>
<p>Repeat step 4 for all your references.</p>
</li>
<li>
<p>Now select the text you want to link to originate from, say the number 1 between the square brackets, and click <code class="highlighter-rouge">Ctrl+K</code>, select <code class="highlighter-rouge">Place in This Document</code> in the left pane and click on the bookmark <code class="highlighter-rouge">r01</code>. Make sure text to display shows the selected text, ie. the number 1 here.</p>
</li>
<li>
<p>Repeat Step 6 for all highlighted occurrences. For references like [17-19], add only one link from <code class="highlighter-rouge">17-19</code> to bookmark <code class="highlighter-rouge">r17</code> and for [37-40,45], add one link from <code class="highlighter-rouge">37-40</code> to bookmark <code class="highlighter-rouge">r37</code> and one from <code class="highlighter-rouge">45</code> to bookmark <code class="highlighter-rouge">r45</code>.</p>
<p><img src="/images/2020-11-12-Add-cross-referencing-in-your-paper-pdfs-created-with-MS-Word/Bookmark.png" alt="Bookmark" title=" Here's how we create a Bookmark." /></p>
</li>
<li>
<p>Remove all the highlights and probably the link decorations with blue fonts and underlines as well. Research papers have uniform font settings. So select <code class="highlighter-rouge">Ctrl+A</code>, remove the highlights, select the font color as Black and press <code class="highlighter-rouge">Ctrl+U</code> twice to remove underlines.</p>
</li>
</ol>
<p>Here we’ve primarily covered only cross-referencing citations with references, but this can be easily extended to sections, subsections, tables, figures or any other place in the document by bookmarking at that location with <code class="highlighter-rouge">Ctrl+Shift+F5</code> , naming it and pressing <code class="highlighter-rouge">Enter</code>. Then just go to the place where the link should originate and press <code class="highlighter-rouge">Ctrl+K</code> and add the destination as the correct bookmark. I usually use the naming convention of <code class="highlighter-rouge">r01...</code> for references, <code class="highlighter-rouge">f01...</code> for figures, <code class="highlighter-rouge">t01...</code> for tables, <code class="highlighter-rouge">s01...</code> for sections and <code class="highlighter-rouge">ss01...</code> for sub-sections, but feel free to use any convention you want.</p>
<h2 id="here-are-some-researchers-and-their-papers-using-this-method">Here are some researchers and their Papers using this Method</h2>
<ul>
<li><a href="https://orcid.org/0000-0002-4351-2108">A. J. Paul</a>, “<a href="https://arxiv.org/abs/2009.11225v2">Randomised fast no-loss expert system to play tic-tac-toe like a human</a>,” Cogn. Comput. Syst., Sep. 2020, doi: <a href="https://doi.org/10.1049/ccs.2020.0018">10.1049/ccs.2020.0018</a>. <em>Click on the paper title to reach the ArXiv v2 of the paper typeset by the author, with this method.</em></li>
</ul>
<p><em>… and many more to come!!</em></p>
<h2 id="congratulations-">Congratulations !!</h2>
<p><strong><em>You’ve made your first cross-referenced pdf in MS Word!</em></strong> Do note cross-referencing might not appear to work on some mobile pdf viewers even if it is enabled in the pdf, but does work on the Desktop, with Adobe, Google Chrome etc.</p>
<p>If you know such a free tool exists to do this for MS Word documents, do drop it in the comments, and we’d love to mention it here. In future, someone might create a script/macro for this, making it even easier. If you create that, or know someone who does, do reach out to us in the comments, we’d love to give it a shoutout and even go and make a post about it benefitting researchers across the globe.</p>
<p><strong><em>Finally, if this article helped you, we’d love to hear about it in the comments and if you have used it in a paper, we’d love to feature your paper here as well.</em></strong></p>Aditya Jyoti PaulIf you’re here, you’ve in all probability written the first draft of your paper and made a pdf for submission to your favorite journal/conference or open-access repository. Congratulations, pat yourself on the back, the hard part is now behind you. In a series of blog posts, I’m going to tell you how you can make your articles easier to read and understand and thus get more cited!A Quick Overview of QUIC and HTTP/32020-11-10T00:00:00-06:002020-11-10T00:00:00-06:00https://blog.carlresearch.org/quic%20%20http3/web/2020/11/10/A-Quick-Overview-of-QUIC-and-HTTP3<p>It’s quite evident how much we are dependent on the web. While some of us brag about being web developers, others are still intimidated by the information the web overflows us with. Ever wondered how the web works behind the scenes?</p>
<h3 id="what-really-happens-when-you-hit-wwwjohndoecom">What really happens when you hit www.johndoe.com?</h3>
<p>I’ll try to keep it as simple as possible, so here it goes— every domain name is associated with an IP address that the web understands. When you enter <em>www.johndoe.com</em>, it initially looks up for its IP address in the browser cache. If it is not found in browser cache, it looks up for it in the router cache and ISP cache.</p>
<p><img src="/images/2020-11-10-A-Quick-Overview-of-QUIC-and-HTTP3/johndoe.com.png" alt="johndoe.com" title="What happens when you click on johndoe.com" /></p>
<p>If the above steps don’t return the IP address, it is then requested to the root server which tells you from where you can get the information, i.e top level domain (TLD). The TLD let’s you know the IP address of your domain name (search input) and then you can initiate a connection with the domain.</p>
<p><img src="/images/2020-11-10-A-Quick-Overview-of-QUIC-and-HTTP3/TCP_3_Way_Handshake.png" alt="TCP 3-Way Handshake" title="TCP 3-Way Handshake" /></p>
<p>The connection is established in three steps and is known as <a href="https://docs.microsoft.com/en-us/troubleshoot/windows-server/networking/three-way-handshake-via-tcpip" title="TCP 3-way handshake">TCP 3-way handshake</a>. After successfully connecting with the server, you can then communicate with the domain and send requests according to your needs.</p>
<p>To understand the web, we have put some layers to how this awesome sequence works out. The Open Systems Interconnection (OSI) model acts as a reference tool for understanding communication and transfer of data between systems in a network. The OSI model comprises seven layers, each layer performing specific functions to support its neighboring layers. This layered stack basically provides flexibility, and hence these layers are quite loosely coupled.</p>
<p><img src="/images/2020-11-10-A-Quick-Overview-of-QUIC-and-HTTP3/Layers_of_OSI.png" alt="OSI Layers" title="7 Layers OSI" /></p>
<ul>
<li>
<p>Physical Layer: It consists of physical devices such as <em>hubs, repeaters, modems,</em> etc. which are responsible for the transfer of raw unstructured data in the form of <a href="https://web.stanford.edu/class/cs101/bits-bytes.html" title="bits">bits</a>. It defines the topology of devices in a network and transmits data by converting the digital bits into electrical, optical, or radio signals.</p>
</li>
<li>
<p>Data Link Layer: It comprises networking components such as <em>NIC, Ethernet,</em> etc. to ensure error-free transmission of data between the nodes in a network. It has two sub-layers, Medium Access Control (MAC) layer that helps in flow control and multiplexing of nodes over the network, and Logical Link Control (LLC) layer that provides flow and error control along with identification of network layer protocols.</p>
</li>
<li>
<p>Network Layer: Devices like <em>routers</em> work at the network layer to assign the destination address in the packet headers. The routers are responsible for finding the optimal path from the available multiple paths to send the data to the desired destination.</p>
</li>
<li>
<p>Transport Layer: This layer consists of protocols like <em>Transmission Control Protocol (TCP)</em> and <em>User Datagram Protocol (UDP)</em> that help in end-to-end delivery of data in the form of small units called <a href="https://www.geeksforgeeks.org/difference-between-segments-packets-and-frames/" title="segments">segments</a>. It is responsible for the sequencing and reassembling of segmented data along with error control.</p>
</li>
<li>
<p>Session Layer: Implementations of session layer include <em>Zone Information Protocol (ZIP)</em> and <em>Session Control Protocol (SCP)</em> that make use of remote procedure calls (RPC). Session layer is responsible for the establishment, maintenance, authentication and security between end user application processes.</p>
</li>
<li>
<p>Presentation Layer: Also known as syntax layer, it translates data into the form that the application accepts. It also assists in compression and encryption of the data if required by the application layer. Protocols like <em>Secured Socket Layer (SSL)</em> and <em>File Transfer Protocol (FTP)</em> are implemented at the presentation layer.</p>
</li>
<li>
<p>Application Layer: This layer is the closest to the user and hence includes applications like <em>Telnet</em> and <em>Simple Mail Transfer Protocol (SMTP)</em>. Application layer identifies resource availability, communication partners and synchronizes communication. Hence it acts as a window for application services to access the network and display the information received by lower layers to the user.</p>
</li>
</ul>
<p>Before we understand what is QUIC, we need to understand what problems it solves.</p>
<h3 id="http-1--http-2">HTTP 1 → HTTP 2</h3>
<p>If you’re using HTTP 1, your browser would be opening parallel connections to open up things at the same time. It doesn’t actually circumvent the <a href="https://en.wikipedia.org/wiki/Head-of-line_blocking" title="head-of-line blocking">head-of-line blocking</a> problems, but surely makes them occur less frequently. It works well for the HTTP 1 but it certainly has its overheads, as it has to set-up as well as maintain all those numerous connections. By and large, HTTP 1 has three main issues:</p>
<ul>
<li>
<p>TCP head-of-the-line blocking</p>
</li>
<li>
<p>HTTP head-of-the-line blocking</p>
</li>
<li>
<p>4-RTT connection setup</p>
</li>
</ul>
<p>If our connection set-up is slow, and we incur packet loss, other packets can be blocked even though they might have arrived at the client, and if we have a slow first resource on HTTP, then it can also block the things lined behind it. The last two have solutions inferred, but they themselves have a lot of overhead by itself.</p>
<p>The <a href="https://www.42gears.com/blog/why-its-time-to-enable-tls-1-2/" title="TLS 1.2">TLS 1.2</a> had made a total of 4 round trips in order to set up secured connections. To optimize this time trade-off, the simplest thing to do was to do two things in one round trip. It was possible to implement this in some scenarios of TLS 1.2 and was the default for <a href="https://wiki.openssl.org/index.php/TLS1.3" title="TLS 1.3">TLS 1.3</a>, its successor, having a total of 3 round trips. To optimize this even closer, the TCP and TLS could work together by pulling out some strings, and this technology was called <a href="https://en.wikipedia.org/wiki/TCP_Fast_Open#:~:text=In%20computer%20networking%2C%20TCP%20Fast,TCP" title="TCP Fast Open">TCP Fast Open</a>, where the user could send some extra data in the initial SYN packet. This was also beneficial as we were able to achieve twice the performance that we initially had and now what really was needed was a holy grail, to perform everything in just one single task. Along with the TLS evolution, HTTP went under transformation too. From the journey of HTTP 1.1 to HTTP 2, it solved the head-of-the-line blocking problem as it became better and smarter.</p>
<p>Now after these amazing transformations, all we wish was the ability of HTTP to perform multiple things at once. This certainly wasn’t feasible on HTTP 1, as it sends all the information in one big block without any demarcation to which resources the individual blocks belong to.
This was achieved by <em>multiplexing</em>. Hence, HTTP 2 solves two problems at once - the HTTP head-of-the-line blocking problem and the overhead of the mitigation as seen above.</p>
<p>Yet, the TCP head-of-the-line blocking problem in regards to the loss of packet isn’t resolved. However, it was observed that <a href="https://www.researchgate.net/publication/308873246_Is_HTTP2_really_faster_than_HTTP11" title="speed analysis">HTTP 2 can be 5 times slower than HTTP 1</a> on a network with packet traffic. By now, you might be thinking that this can be resolved by introducing a new version as in previous use cases. Yet we know that there exists no TCP 2.0 . The reason being, that TCP is too popular and widespread to be modified. According to the definitions of the Internet, we all know that it is an interconnection of several devices. Now, these devices are running on their own implementations of TCP. This means, that if we try to change these TCP implementations, there is a high probability that we break some of these <a href="https://en.wikipedia.org/wiki/Middlebox" title="middle-box">middle-box</a> implementations, and hence if we wish to modify these, we have to wait until all these humongous implementations have added support for it before we can actually deploy it at a large scale.</p>
<p>On the whole, in order to solve the TCP head-of-the-line problem, we can either wait for a whole another decade so that everyone is on the same boat, or, we can make a bold choice, that TCP isn’t evolvable anymore and hence needs a replacement.</p>
<h3 id="enter-udp">Enter UDP</h3>
<p>UDP isn’t like the TCP at all. It is fast and doesn’t care about the packet loss.
<img src="/images/2020-11-10-A-Quick-Overview-of-QUIC-and-HTTP3/TCP_vs_UDP.png" alt="TCP vs UDP" title="TCP vs UDP" /></p>
<p><a href="https://ieeexplore.ieee.org/document/8537265" title="QUIC">QUIC</a> still uses TLS 1.3 . It still has that zero RTT goodness, it is built on top of UDP, and uses the HTTP 2 semantics. QUIC incorporates the multiplexing from HTTP 2 and re-implements in-order reliability on top of UDP custom top packet loss recovery logic.
<img src="/images/2020-11-10-A-Quick-Overview-of-QUIC-and-HTTP3/Layers_of_QUIC.png" alt="Layers of QUIC" title="Layers of QUIC" /></p>
<p>This means that in QUIC if one packet is facing problems, others don’t have to be blocked due to it. Thus solving the TCP head-of-the-line problem! For solving this one problem, it is evident that a lot of effort is required at the backend. Also we know that HTTP 2 and TLS 1.3 work absolutely fine on TCP as well. So, the question arises: was it really worth the effort to solve that one TCP head-of-the-line blocking problem? The answer is <strong>NO</strong>.</p>
<p>Hence while developing QUIC, the developers strived to solve all the other problems as well. Consequently, QUIC is an amalgamation of everything one has known about networks over the past three decades. It’s like Christmas in a bowl!</p>
<h3 id="additional-features-of-quic">Additional features of QUIC</h3>
<h4 id="focuses-on-security">Focuses on security</h4>
<p>One of the major deviations of QUIC from the vulnerable TCP is its design goal of providing a secure-by-default transport protocol. QUIC achieves this by providing security features, like encryption and authentication, that are usually managed by higher layer protocols like TLS from the transport protocol itself.</p>
<h4 id="prevents-middle-box-meddling-through-encryption">Prevents middle box meddling through encryption</h4>
<p>QUIC is more flexible than TCP and encrypts everything including its own metadata. Therefore the less these middle boxes get to see, the lesser they can modify. This is indeed useful for QUIC and its users, but not for the people who make these middle boxes. A lot of deliberation has been made just to come to a conclusion whether a single bit should be visible to the middle boxes or not.</p>
<h4 id="connection-id-and-multipath">Connection ID and multipath</h4>
<p>It provides easy switching over networks. QUIC takes into account how people actually use the Internet in daily life, for say, when one is at home they are usually on WiFi, but once they step out, they switch to 4G. This closes down the TCP connection they would have established and reconnects as they now have a new IP address. However, in QUIC this is not so tiresome. QUIC instead assigns you a unique connection ID that remains the same irrespective of how many times you change your IP address. Icing on the cake, it also has the capability to use WiFi and 4G both at the same time; two networks along with extra bandwidth, which is the idea behind multipath)</p>
<h4 id="custom-congestion-control">Custom congestion control</h4>
<p>It is the mechanism that prevents you from overloading the network by sending too much data. TCP has this feature as well, but it is not fairly optimal. It uses a single general-purpose algorithm and uses it for all types of connection. But it is not so generalized in case of QUIC. For instance, like a NETINFO API that lets you see what connection you’re currently using and how much bandwidth you have, it provides the perfect micro optimization for individual user and connection types for the exact moment, and even for the exact page one is trying to serve them, which makes HTTP 2 server push more practically applicable.</p>
<h3 id="quic-performance-check">QUIC Performance Check</h3>
<p>After the plethora of features that QUIC empowers us with, how much performance gain can we actually expect? And the answer is, WE DON’T KNOW! QUIC was originally developed by Google a couple of years ago. They initially deployed QUIC on their servers, and on Chrome, and is currently <a href="https://www.ietfjournal.org/quic-bringing-flexibility-to-the-internet/" title="QUIC and the Internet">serving 7% of the total Internet</a> space. QUIC hence has been battle-tested, but, only by Google. Google; the name eventually comes with trust. We like Google. If Google says something works, we say “standardize it”. This was the story of QUIC in a nutshell over past years. When we got the new <a href="https://mailarchive.ietf.org/arch/msg/quic/RLRs4nB1lwFCZ_7k0iuz0ZBa35s/" title="IEFT and QUIC">IEFT version</a> of QUIC, although it was similar to Google’s version in concept, yet it was changed to a great extent in terms of its implementation. There are several implementations of it, but none of them is even remotely ready for any type of performance testing, let alone browser integration.</p>
<h3 id="lets-talk-numbers">Let’s talk numbers</h3>
<p>According to Google, they found 3.6 - 8% improvement on an average over desktop and mobile devices. I’d be lying if I say I wasn’t disappointed by this. But these numbers represent an average. In 99% percentile, it shows an improvement of over 14-16%, which is indeed impactful. It might be quite evident by now that most of this improvement is due to the 0 RTT. But, one can see the 0 RTT only on servers that you’ve somehow seen/accessed before. When using mobile devices, one is likely to move around and hence Google load balances might send them to different data centers that they’ve never been before. This certainly justifies the unequal improvement rates over desktop and mobile devices.</p>
<p>Before you completely get all carried away in the numbers and wondering if QUIC really changed your life, let me recall for you why at the first place we switched to QUIC; and the answer is lossy networks, which is often misinterpreted as loss due to congestion. According to Google statistics, QUIC witnessed <a href="https://research.google/pubs/pub46403/" title="video buffering">20% less video buffering</a> on contents in India. Another <a href="https://www.researchgate.net/publication/318801580_QUIC_Better_for_what_and_for_whom" title="reference paper">paper</a> shows that there is a 14% of actual page load time improvement in the actual browser, which sounds pretty good. A <a href="https://www.researchgate.net/publication/302585207_How_quick_is_QUIC" title="conference paper">conference paper</a> tested QUIC with and without packet loss, and ofcourse QUIC is going to be comparatively slower with packet loss, but only 20% as compared to the 200% of HTTP/2 in most cases. Ok wow. But there are always two sides of a coin. You might be wondering why am I not citing other papers but quote the exact opposite results to the one cited till now. Well, hold your beer, here they come. There is one <a href="https://www.researchgate.net/publication/317639523_Not_so_QUIC_A_Performance_Study_of_DASH_over_QUIC" title="reference paper">paper</a> that says that QUIC is terrible for video streaming, with around 75% less Mbps than TCP for DASH streaming. Another <a href="https://www.researchgate.net/publication/321068535_Taking_a_long_look_at_QUIC_an_approach_for_rigorous_evaluation_of_rapidly_evolving_transport_protocols" title="conference paper">conference paper</a> says that if you have an inconsistent latency which causes packets to be re-ordered, QUIC is 100% than TCP. An old <a href="https://www.researchgate.net/publication/280547975_HTTP_over_UDP_an_experimental_investigation_of_QUIC" title="reference paper">paper</a> says that QUIC can have 30% slower page load time if it incurs packet loss and low bandwidth.</p>
<h3 id="conclusion">Conclusion</h3>
<p>So where are we in terms of final QUIC and HTTP/3 deployment in the world? It is expected that we will see rapidly increased rollouts of QUIC and HTTP/3 by clients by the end 2020, as well as higher volume testing on pre-release channels. It will be followed by clients turning QUIC and HTTP/3 on in their stable releases. Furthermore, it is believed that QUIC and HTTP/3 will become the de-facto mainstream web protocol stack in 2021.</p>
<h3 id="further-reading">Further Reading</h3>
<ul>
<li>
<p><a href="https://quiche.googlesource.com/quiche" title="QUICHE">QUICHE</a></p>
</li>
<li>
<p><a href="https://storage.googleapis.com/pub-tools-public-publication-data/pdf/8b935debf13bd176a08326738f5f88ad115a071e.pdf" title="Design and Internet scale deployemnt">Design and Internet scale deployemnt</a></p>
</li>
<li>
<p><a href="https://www.csoonline.com/article/3564253/6-ways-http-3-benefits-security-and-7-serious-concerns.html" title="HTTP/3 Security">HTTP/3 Security</a></p>
</li>
</ul>
<hr />
<h3 id="author">Author</h3>
<p><a href="https://github.com/shubhangi-singh21" title="GitHub profile">Shubhangi Singh</a></p>
<hr />Shubhangi SinghIt’s quite evident how much we are dependent on the web. While some of us brag about being web developers, others are still intimidated by the information the web overflows us with. Ever wondered how the web works behind the scenes?How sharp is your Memory? Check it with this Memory Game2020-08-20T00:00:00-05:002020-08-20T00:00:00-05:00https://blog.carlresearch.org/speech%20recognition/python/pyttsx3/2020/08/20/how-sharp-is-your-memory<h2 id="introduction">Introduction</h2>
<p>Hey! This is Sanskriti. Hope you all are doing well in this lockdown and using your time well to do productive things. So one of these days, my younger cousin wanted to play something with me, we were on a call. I remembered the memory game I used to play with my mom when I was a kid. My mom used to say the name of an object, I had to add one more object to the list, likewise we had to remember all the old objects in the list in the order and also add the new one. I started playing this game with my cousin but after some time, we both started forgetting the list and neither of us couldn’t point out the mistakes of each other, therefore we didn’t have a winner. So that day I decided to computerise this game with speech integration. This could solve two problems:</p>
<ul>
<li>
<p>Computer’s memory is definitely better than human memory, so you won’t have to care about the right order to tally your responses with.</p>
</li>
<li>
<p>If you don’t have a partner to play along with you, you could play it with the computer. So making the traditional memory game that we have been playing since childhood more interactive, fun and easy to play!</p>
</li>
</ul>
<p><img src="/images/blog_1/memory_game_flowchart.jpeg" alt="" title="Flowchart" /></p>
<h2 id="step-1-generate-random-numbers-and-append-them-in-a-list">Step 1: Generate random numbers and append them in a list</h2>
<p>To develop this game, the first step was to automate the generation of random numbers that were supposed to be memorised by the player. So I wrote a script in python and used an inbuilt function randint() of the random module(available in the latest versions of python i.e, python 3 onwards). Here, I have given the code snippet to print the whole sequence of numbers, but in the actual game, I have printed only the last number of the list. Rest of the numbers stay in list for verification with the user’s input but are not printed.</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">random</span>
<span class="k">while</span><span class="p">(</span><span class="n">f</span><span class="o">==</span><span class="mi">0</span><span class="p">):</span>
<span class="c1">#generate random number
</span> <span class="n">digit</span><span class="o">=</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">9</span><span class="p">)</span>
<span class="n">sequence</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">digit</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="n">sequence</span><span class="p">)</span>
</code></pre></div></div>
<h3 id="how-are-random-integers-generated">How are random integers generated?</h3>
<p>Even the most random data generated with Python is not fully random in the scientific sense. It is pseudorandom, generated with a pseudorandom number generator (PRNG). It starts with a random number, known as the seed, and generates a pseudo-random sequence by performing some operation on that value. Each seed value will correspond to a sequence of generated values for a given random number generator. That is, if you provide the same seed twice, you get the same sequence of numbers twice.</p>
<p>The randint() function uses the <a href="https://github.com/python/cpython/blob/master/Modules/_randommodule.c">Mersenne Twister</a> PRNG algorithm and takes system current time as the seed so the value of seed keeps changing at every execution of the program. The randint() function can take two integer arguments , a start number and an end number, both inclusive. The function then generates numbers only in this range.</p>
<h2 id="step-2-clear-the-output-from-screen">Step 2: Clear the output from screen</h2>
<p>Next step was to clear the output (randomly-generated numbers) from the console after a few seconds for which I used time.stay() function from time library, again an in-built library in python and clear_output() function from IPython.display library. I added these two functions inside the while loop so that the old output gets cleared in every new level.</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">time</span>
<span class="kn">from</span> <span class="nn">IPython.display</span> <span class="kn">import</span> <span class="n">clear_output</span>
<span class="k">while</span><span class="p">(</span><span class="n">f</span><span class="o">==</span><span class="mi">0</span><span class="p">):</span>
<span class="c1">#generate random number
</span> <span class="n">digit</span><span class="o">=</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">9</span><span class="p">)</span>
<span class="n">sequence</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">digit</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="n">sequence</span><span class="p">)</span>
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="n">clear_output</span><span class="p">(</span><span class="n">wait</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</code></pre></div></div>
<h2 id="step-3-recognising-speech">Step 3: Recognising speech</h2>
<p>The most important step was to now integrate a speech recognition module with the game. For that, first you need to download the module, I did it using my pip installer. However, PyAudio Module is a dependency for the SpeechRecognition, and unfortunately you cannot download it directly using pip installer, you will need to use pipwin. After installing the modules, you need to create a function that can be reused to take the input from the user as and when required and compare it to the sequence we have already defined. I used speech recognition by Google API since it gives you the default API key for free. Therefore, an active internet connection is necessary throughout the game to play.</p>
<p><strong>Special tip:</strong> <em>Consider using a try and except block wherever possible so that if anything ever goes wrong, you have a chance to continue the script by returning the same function</em></p>
<p>Here, in the try block, I have typecasted the audio recognized as integer type, so that if due to some error in recognition, a string is recogised by the google cloud, the exception block would catch it and return the recogise() function again.</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">speech_recognition</span> <span class="k">as</span> <span class="n">sr</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">sr</span><span class="o">.</span><span class="n">Recognizer</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">recognise</span><span class="p">():</span>
<span class="k">with</span> <span class="n">sr</span><span class="o">.</span><span class="n">Microphone</span><span class="p">()</span> <span class="k">as</span> <span class="n">source</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="s">"Speak the number"</span><span class="p">)</span>
<span class="n">audio</span> <span class="o">=</span> <span class="n">r</span><span class="o">.</span><span class="n">listen</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">timeout</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">s</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">sp</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">"You said "</span><span class="p">,</span><span class="n">s</span><span class="p">)</span>
<span class="k">return</span> <span class="n">s</span>
<span class="k">except</span> <span class="nb">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">"Didn't get you, can you say it again?"</span><span class="p">)</span>
<span class="k">return</span> <span class="n">recognise</span><span class="p">()</span>
</code></pre></div></div>
<h3 id="how-is-your-voice-recognized">How is your voice recognized??</h3>
<p>Firstly, your speech is converted from physical sound to an electrical signal with a microphone, and then to digital data with an analog-to-digital converter. Then, powerful neural network models are used to transform the features and reduce the dimensionality of signals to simplify the speech. Voice activity detectors (VADs) are also used to reduce an audio signal to only the portions that are likely to contain speech. This prevents the recognizer from wasting time analyzing unnecessary parts of the signal.</p>
<p>In the modern speech recognition models like the <a href="https://en.wikipedia.org/wiki/Hidden_Markov_model">Hidden Markov Model</a>, the speech signal is divided into 10-millisecond fragments so that it can be approximated as a stationary process. The power spectrum of each fragment, (a plot of the signal’s power as a function of frequency) is mapped to a vector of real numbers known as <a href="https://en.wikipedia.org/wiki/Cepstrum">cepstral</a> coefficients. The final output of the HMM is a sequence of these vectors.</p>
<p>To decode the speech into text, groups of vectors are matched to one or more <a href="https://en.wikipedia.org/wiki/Phoneme">phonemes</a>—a fundamental unit of speech. This calculation requires training, since the sound of a phoneme varies from speaker to speaker. A special algorithm is then applied to determine the most likely word (or words) that produce the given sequence of phonemes.</p>
<p><img src="/images/blog_1/speech_recognition_flowchart.jpeg" alt="" title="Voice Recognition Steps courtesy Packt Publishing" /></p>
<h2 id="step-4-making-the-computer-interact-with-player">Step 4: Making the computer interact with player</h2>
<p>The last step was to make the game more interactive. So, I had used the pyttsx3 module. It is a module that converts string text into speech. You can also set the properties of th e computer voice using the function setproperty(), you can change several attributes of speech, male/female voice, speed, and many other things as per your requirements in a function. Next you directly need to call the function wherever you want in the program, passing the text to be spoken as an argument.</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">pyttsx3</span>
<span class="k">def</span> <span class="nf">speak</span><span class="p">(</span><span class="n">text</span><span class="p">):</span>
<span class="n">engine</span> <span class="o">=</span> <span class="n">pyttsx3</span><span class="o">.</span><span class="n">init</span><span class="p">()</span>
<span class="n">engine</span><span class="o">.</span><span class="n">setProperty</span><span class="p">(</span><span class="s">'rate'</span><span class="p">,</span> <span class="mi">220</span><span class="p">)</span>
<span class="n">voices</span> <span class="o">=</span> <span class="n">engine</span><span class="o">.</span><span class="n">getProperty</span><span class="p">(</span><span class="s">'voices'</span><span class="p">)</span>
<span class="n">engine</span><span class="o">.</span><span class="n">setProperty</span><span class="p">(</span><span class="s">'voice'</span><span class="p">,</span> <span class="n">voices</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="nb">id</span><span class="p">)</span>
<span class="n">engine</span><span class="o">.</span><span class="n">say</span><span class="p">(</span><span class="n">text</span><span class="p">)</span>
<span class="n">engine</span><span class="o">.</span><span class="n">runAndWait</span><span class="p">()</span>
</code></pre></div></div>
<h2 id="conclusion">Conclusion</h2>
<p>Hope you enjoy building and playing this game. You can check my github repo <a href="https://github.com/sanskritikhare142/Memory-game-using-speech">github repo</a> for the complete code.</p>
<p>Let me know how you renovate the game and take it forward.</p>
<p>Stay home, Stay safe and keep improving your memory! :)</p>
<p>Cheers,</p>
<p>Sanskriti Khare</p>Sanskriti KhareIntroduction